我有一张表
table(a,b,c,date(此字段是日期类型),e,f,g)
表中数据除了date字段不一样,其他都一样求助删除这样冗余数据的方法

解决方案 »

  1.   

    你要留下什么样的数据?或者你要删除什么样的数据?
    --如下,留下 时间最大的数据
    delete from table where (a,b,c,date,e,f,g) not in 
    (select a,b,c,max(date),e,f,g from table group by a,b,c,e,f,g) 
      

  2.   

    先用分组的方法将冗余数据找出来。然后用1楼的方法删除冗余数据DELETE FROM TABLE WHERE  DATE NOT IN (SELECT MAX(date) AS DATE  FROM (
    SELECT DATE  FROM TABLE GROUP BY DATE HAVING(COUNT(1)>1)) t) 
      

  3.   

    删除重复数据,只保留一条:delete from tablename table1
     where rowid < (select max(rowid)
                      from tablename table2
                     where table1.a = table2.a
                       and table1.b = table2.b
                       and table1.c = table2.c
                       and table1.e = table2.e
                       and table1.f = table2.f
                       and table1.g = table2.g)