分类: SQLServer
2013-02-22 17:55:47
在oracle中 可以直接使用in 来 匹配,sql server 中不可以使用in关键字多字段匹配,所以选择使用 and
连接。下面用Min()函数保留组前面一条记录,如果保留最后一条记录用Max()函数。
select * from test2 where (t1 in (select t1 from test2 group by t1 having count(*) >1 )) and (t2 in (select t2 from test2 group by t2 having count(*) >1 )) and tid not in (select min(tid) from test2 group by t1 having count(*) >1 ) and tid not in (select min(tid) from test2 group by t2 having count(*) >1 )
在oracle中删除多余的重复项
select * from test2 where (t1,t2) in (select t1,t2 from test2 group by t1,t2 having(count(*)>1 ))