1、数据类似如下:
id         值
----       ----
1          5
1          4
1          3
1          2
2          6
2          5
2          5
3          5
3          5
4          7
5          5
6          5
6          1求脚本,按ID分组每组只留下最大值,其他数据删除,最后结果如下:
ID         值
---        ---
1          5
2          6
3          5
4          7
5          5
6          5

解决方案 »

  1.   

    SELECT ID,MAX(值) FROM TABLE
     GROUP BY ID  ,楼主应该多看书啊
      

  2.   

    delete from table1 t
    where exists(
      select 1 from table1 where id=t.id
      and (VAL>t.VAL
      or VAL=t.VAL and rowid<t.rowid))
      

  3.   

    delete from tb t where 值 not in (select max(值) from tb where id = t.id)
      

  4.   

    delete from tb a where 值 not in(select max(值) from tb where a.id=id)delete from tb where 值 not in(select max(值) from tb where group by id)