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

解决方案 »

  1.   

    select billid,goodsid from card group by billid,goodsid having count(1)>1
      

  2.   

    select billid,goodsid from card
    group by billid,goodsid
    having count(*)>1
      

  3.   

    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)
      

  4.   

    select billid,goodsid from card group by billid,goodsid having count(1) > 1
      

  5.   

    create table t(
      billid int,
      goodsid int
    )
    insert t
    select 1,102 union all
    select 1,103 union all
    select 2,103 union all
    select 2,105 union all
    select 2,103 union all
    select 3,118 union all
    select 4,102 union all
    select 4,108select a.* from t a
    inner join(
      select billid,goodsid from t group by billid,goodsid having count(*)>=2
    )b on a.billid=b.billid and a.goodsid=b.goodsid--result:
    billid goodsid 
    -------------------
    2       103
    2       103
      

  6.   

    select billid,goodsid from card group by billid,goodsid having count(*) >1