-1

私は次の表を持っています:

    CREATE TABLE ta91 (
    id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
    date INTEGER, 
    _520  INTEGER, 
    _530 INTEGER,
    _540 INTEGER,
    _550 INTEGER,
    _560 INTEGER,
    _570 INTEGER,
    _580 INTEGER,
    _590 INTEGER,
    _600 INTEGER,
    _610 INTEGER,
    _620 INTEGER,
    _630 INTEGER,
    _640 INTEGER,
    _650 INTEGER,
    _660 INTEGER,
    _670 INTEGER,
    _680 INTEGER,
    _690 INTEGER,
    _700 INTEGER,
    _710 INTEGER,
    _720 INTEGER,
    _730 INTEGER,
    _740 INTEGER,
    _750 INTEGER,
    _760 INTEGER,
    _770 INTEGER,
    _780 INTEGER,
    _790 INTEGER,
    _800 INTEGER,
    _810 INTEGER,
    _820 INTEGER,
    _830 INTEGER,
    _840 INTEGER,
    _850 INTEGER
)

値を使用して:

INSERT INTO "someTable" VALUES ("10","1355480306018","1","0","0","0","0","1","0","0","0","0","1","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0");
INSERT INTO "someTable" VALUES ("11","1355480307044","1","0","0","0","0","0","0","0","1","0","0","0","1","0","0","0","0","0","1","1","1","1","0","0","0","0","0","0","0","0","0","0","0","0");
INSERT INTO "someTable" VALUES ("12","1355480308027","1","0","0","0","0","0","0","0","1","0","0","0","1","0","0","0","0","0","1","1","1","1","0","0","0","0","0","0","0","0","0","0","0","0");
INSERT INTO "someTable" VALUES ("13","1355480309033","1","0","0","0","0","1","0","0","0","0","1","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0");
INSERT INTO "someTable" VALUES ("14","1355480310038","1","0","0","0","0","1","0","0","0","0","1","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0");
INSERT INTO "someTable" VALUES ("15","1355480311043","1","0","0","0","0","0","0","0","1","0","0","0","1","0","0","0","0","0","1","1","1","1","0","0","0","0","0","0","0","0","0","0","0","0");
INSERT INTO "someTable" VALUES ("16","1355480312043","1","0","0","0","0","0","0","0","1","0","0","0","1","0","0","0","0","0","1","1","1","1","0","0","0","0","0","0","0","0","0","0","0","0");
INSERT INTO "someTable" VALUES ("17","1355480313048","1","0","0","0","0","1","0","0","0","0","1","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0");

値が0/1またはから切り替わる回数をカウントするにはどうすればよいですか。SQLの各列に直接1/0?

私はデータベースにアクセスするためにSystem.Data.SQLite.dll1.0.82.0でc#を使用しています

4

1 に答える 1

1

仮定

  1. sqlite以外の移植性要件はありません。
  2. 連続しidた値;
  3. 0から1と1から0の両方のスイッチの合計回数を(列ごとに)カウントする必要があります。
  4. someTableあなたのINSERTステートメントのように、テーブル名があります。

あなたはこれを使うことができます:

SELECT SUM(a._520<>b._520) AS s_520,
       SUM(a._530<>b._530) AS s_530,
       SUM(a._540<>b._540) AS s_540,
       SUM(a._550<>b._550) AS s_550,
       SUM(a._560<>b._560) AS s_560,
       SUM(a._570<>b._570) AS s_570,
       SUM(a._580<>b._580) AS s_580,
       SUM(a._590<>b._590) AS s_590,
       SUM(a._600<>b._600) AS s_600,
       SUM(a._610<>b._610) AS s_610,
       SUM(a._620<>b._620) AS s_620,
       SUM(a._630<>b._630) AS s_630,
       SUM(a._640<>b._640) AS s_640,
       SUM(a._650<>b._650) AS s_650,
       SUM(a._660<>b._660) AS s_660,
       SUM(a._670<>b._670) AS s_670,
       SUM(a._680<>b._680) AS s_680,
       SUM(a._690<>b._690) AS s_690,
       SUM(a._700<>b._700) AS s_700,
       SUM(a._710<>b._710) AS s_710,
       SUM(a._720<>b._720) AS s_720,
       SUM(a._730<>b._730) AS s_730,
       SUM(a._740<>b._740) AS s_740,
       SUM(a._750<>b._750) AS s_750,
       SUM(a._760<>b._760) AS s_760,
       SUM(a._770<>b._770) AS s_770,
       SUM(a._780<>b._780) AS s_780,
       SUM(a._790<>b._790) AS s_790,
       SUM(a._800<>b._800) AS s_800,
       SUM(a._810<>b._810) AS s_810,
       SUM(a._820<>b._820) AS s_820,
       SUM(a._830<>b._830) AS s_830,
       SUM(a._840<>b._840) AS s_840,
       SUM(a._850<>b._850) AS s_850
FROM "someTable" a INNER JOIN "someTable" b
ON a.id = b.id-1;

もちろん、私はこれを生成しました。だからあなたはできますか。

于 2013-01-26T14:17:17.387 に答える