表1名称 数据 类别
1 789 a
2 123 a
3 339 a
1 339 b
2 666 b
3 888 b
1 336 c
2 666 c
3 777 c如何选出表1数据列里重复的数据 谢谢
上面例子得结果名称 数据 类别
3 339 a
1 339 b
2 666 b
2 666 c
1 789 a
2 123 a
3 339 a
1 339 b
2 666 b
3 888 b
1 336 c
2 666 c
3 777 c如何选出表1数据列里重复的数据 谢谢
上面例子得结果名称 数据 类别
3 339 a
1 339 b
2 666 b
2 666 c
insert @t select 1, 789, 'a'
insert @t select 2, 123, 'a'
insert @t select 3, 339, 'a'
insert @t select 1, 339, 'b'
insert @t select 2, 666, 'b'
insert @t select 3, 888, 'b'
insert @t select 1, 336, 'c'
insert @t select 2, 666, 'c'
insert @t select 3, 777, 'c'
select * from @t where 数据 in( select 数据 from @t group by 数据 having count(*)>1)
/*名称 数据 类别
----------- ----------- ----
3 339 a
1 339 b
2 666 b
2 666 c*/
select * from t
where exists(select 1 from t as aa where aa.名称 = t.名称)
and
exists(select 1 from t as aa where aa.数据 = t.数据)
and
exists(select 1 from t as aa where aa.类别 = t.类别) order by t.数据
1 339 b
2 666 b
2 666 c
select *
from tb a
where (select count(1) from tb where 数据=a.数据)>=2
名称 数据 类别
3 339 a
1 339 b
2 666 b
2 666 c
**/