日期:2014-05-18  浏览次数:20441 次

sql 筛选重复数据
ID Col1 Col2 Col3

1 A1 a 2012

2 A2 b 2012

3 A3 c 2012

4 A1 a 2000
表中查询结果如上,请问我要筛选 Col1和Col2 相同的数据sql(就是ID 为 1 和 4)语句怎么写呢?

------解决方案--------------------
SQL code
select * from tb t
where exists(select 1 from tb where id!=t.id and col1=t.col1 and col2=t.col2)

------解决方案--------------------
select ID,Col1,Col2,Col3 from(
select px=count(1)over(partition by Col1,Col2,Col3),* from tb)t
where px>=2