当前位置: 代码迷 >> Sql Server >> 帮忙写个SQL语句 检索重复的数据,该怎么解决
  详细解决方案

帮忙写个SQL语句 检索重复的数据,该怎么解决

热度:258   发布时间:2016-04-27 19:25:52.0
帮忙写个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)
  相关解决方案