首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql 筛选重复数据解决思路

2012-06-15 
sql 筛选重复数据ID Col1 Col2 Col31A1a20122A2b20123A3c20124A1a2000表中查询结果如上,请问我要筛选 Col1

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

热点排行