日期:2014-05-17  浏览次数:20690 次

请教一个sql删除特定表内容的方法
有一个表有两个字段:ID(自动递增)和type(任意整数)。

我现在需要删除type=1的条目中除了ID值最大的以外的条目,比如

ID   TYPE
1     1
2     1
3     1
4     2
5     2
6     1

删除后为
4     2
5     2
6     1

请问怎么实现比较简单?

------解决方案--------------------
delete from aa where type=1 and id <(select max(id) from aa where type=1)
aa是你的表名