读书人

sql 筛选重复数据解决思路

发布时间: 2012-06-15 19:37:05 作者: rapoo

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 twhere 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

读书人网 >SQL Server

热点推荐