0

「SULP」という名前のsqliteテーブルがあり、次のようになります。

name year month day hour min ro   
"SULP","12","7","7","0","0","2.41196"   *
"SULP","12","7","7","0","0","2.39269"
"SULP","12","7","7","0","1","2.41117"   *
"SULP","12","7","7","0","1","2.39198"
"SULP","12","7","7","0","2","2.41004"   *
"SULP","12","7","7","0","2","2.39117"
"SULP","12","7","7","0","3","2.40914"   *
"SULP","12","7","7","0","3","2.39043"

* でマークされた行は削除しません

私が試してみました

delete from SULP 
       where exists (select * from 'SULP' as t2 WHERE t2.year=year
       AND t2.month=month AND t2.day=day AND t2.hour=hour AND 
       t2.min=min and ro<>t2.ro order by rowid desc limit 1);

delete from 'SULP' 
      where exists (select * from 'SULP' as t2 WHERE t2.year=year 
      AND t2.month=month AND t2.day=day AND t2.hour=hour AND 
      t2.min=min AND rowid<t2.rowid);

しかし運がない:(

4

3 に答える 3

1

別の解決策:

DELETE FROM SULP WHERE (
    SELECT MIN(ro) FROM SULP AS t2
    WHERE year  = SULP.year
      AND month = SULP.month
      AND day   = SULP.day
      AND hour  = SULP.hour
      AND min   = SULP.min
   ) <> ro;
于 2013-08-30T12:45:57.193 に答える
1

これはあなたが望むことをします:

DELETE FROM SULP
WHERE EXISTS (
SELECT *
FROM SULP t2
GROUP BY name, year, month, hour, min
HAVING SULP.rowid = min(t2.rowid)  
)

SQLFIDDLEを参照してください

于 2013-08-29T17:01:51.620 に答える
0

サブクエリ内では、両方ともテーブルの列を参照しt2.yearます。yeart2

SULP.year外部テーブルを参照するには、次を使用する必要があります。

DELETE FROM "SULP"
WHERE EXISTS (SELECT 1
              FROM "SULP" AS t2
              WHERE t2.year  = SULP.year
                AND t2.month = SULP.month
                AND t2.day   = SULP.day
                AND t2.hour  = SULP.hour
                AND t2.min   = SULP.min
                AND t2.ro    < SULP.ro)
于 2013-08-29T15:58:27.747 に答える