select id1 , id2
from t1
group by id1 , id2
having count(*) > 1

解决方案 »

  1.   

    方法1:
    select t1.id1 , t1.id2 from t1 , 
    (select id1 , id2
    from t1
    group by id1 , id2
    having count(*) > 1) t2
    where t1.id1 = t2.id1 and t1.id2 = t2.id2方法2:(投机取巧:-)
    select id1 , id2
    from t1
    group by id1 , id2
    having count(*) > 1
    union all
    select id1 , id2
    from t1
    group by id1 , id2
    having count(*) > 1
      

  2.   

    Try:select * from table where id1+','+id2 in (
       select id1+','+id2  from table group by id1,id2 having count(*)>1
    )
      

  3.   

    还是不行,报错:“服务器: 消息 245,级别 16,状态 1,行 1
    将 varchar 值 ',' 转换为数据类型为 int 的列时发生语法错误。
      

  4.   

    TRY:
    select * from table where cast(id1 as varchar)+','+cast(id2 as varchar) in (
       select id1+','+id2 from table group by id1,id2 having count(*)>1
    )
      

  5.   

    set nocount on
    declare @t1 table (id1 int,id2 int)
    insert into @t1 values(8,3)
    insert into @t1 values(8,3)
    insert into @t1 values(5,6)
    insert into @t1 values(5,2)
    insert into @t1 values(7,6)
    insert into @t1 values(7,6)select id1,id2 
      from @t1 
     where str(id1)+','+str(id2) not in (select str(id1)+','+str(id2)
                                           from @t1 
                                       group by id1 , id2 
                                         having count(*) = 1)
      

  6.   

    再试试,我记得已经改成这样了,怎么上面没改完。:)
    select * from table where cast(id1 as varchar)+','+cast(id2 as varchar) in (
       select cast(id1 as varchar)+','+cast(id2 as varchar)  from table group by id1,id2 having count(*)>1
    )
      

  7.   

    同意蚂蚁兄,
       select id1,id2 from table where id1+','+id2 in (
       select id1+','+id2  from table group by id1,id2 having count(*)>1)
    注意如果id1、id2两个字段为int或smallint类型,提示先转换为char或varchar即可!
      

  8.   

    declare @t1 table (id1 int,id2 int)
    insert into @t1 values(8,3)
    insert into @t1 values(8,3)
    insert into @t1 values(5,6)
    insert into @t1 values(5,2)
    insert into @t1 values(7,6)
    insert into @t1 values(7,6)select * from @t1 a where exists (select 1 from (select * from @t1 group by id1,id2 having count(*)>1) tem where tem.id1=a.id1 and tem.id2=a.id2)