+ -
当前位置:首页 → 问答吧 → SQL删除只出现一次的数据

SQL删除只出现一次的数据

时间:2011-06-23

来源:互联网

删除某字段中只出现一次的数据如
A B C
1 2 3
2 3 4
1 5 6
上面的A字段中2只出现一次,所以要把那条数据数据。改怎么写

作者: rongguo52013   发布时间: 2011-06-23

delete from table as T where (select count(a) from table where A=T.A)=1

作者: lzp4881   发布时间: 2011-06-23

需要一个标识,比如主键ID,用来区分他们的不同

delete from table t1 where A not in (select A from table where A=t1.A and ID<>t1.ID)

作者: tcwsyt   发布时间: 2011-06-23

SQL code
delete from tb where a in (select a from tb as t where (select count(*) from tb where a = t.a)=1)

作者: aspwebchh   发布时间: 2011-06-23