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

帮忙写个SQL语句 检索重复的数据
比如有一张表 card,

billid goodsid
1 102
1 103
2 103
2 105
2 103
3 118
4 102
4 108
如何把两个键值同时重复的行检索出来呀?
就是把 2 103 检索出来?谢谢

------解决方案--------------------
select billid,goodsid from card group by billid,goodsid having count(1)>1
------解决方案--------------------
select billid,goodsid from card
group by billid,goodsid
having count(*)>1
------解决方案--------------------
SELECT * FROM CARD WHERE BILLID IN (SELECT BILLID FROM CARD HAVING COUNT(BILLID)>1) 
AND GOODSID IN (SELECT GOODSID FROM CARD HAVING COUNT(GOODSID)>1)