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引用year了表的列t2

您必须使用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 回答