用sql语句怎么求 一个表T中 字段A,和字段B数据都相同的 数据。

例表T中 A B C
1 2 h
1 2 j
1 3 l
2 2 k
执行sql语句后,应该得到前两行的数据。

把表名换成你的表
select t1.*
from 表名 t1,
(select a,b from 表名 group by a,b having(count(*)>1)) t2
where t1.a=t2.a and t1.b=t2.b;追问

有没有更简便的方法呢、??
你看这样行不行
Select a,b,c ,count(*) over(partition by a,b) cnt
from T
where cnt > 1

追答

你的方法也很好啊,不过要改,cnt它是识别不到的
select * from(
Select a,b,c ,count(*) over(partition by a,b)cnt
from t)
where cnt> 1

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-17
如果是a和b完全相同可以这样
select a,b from [t] group by a,b

select DISTINCT a,b from [t]
第2个回答  2013-10-17
select tt.A,ta.B from T tt left join T ta on tt.A = ta.B追问

没理解我的意思啊, 我要的是字段A重复,并且字段B也重复的数据。

相似回答