我有一个表,有两个列a,b,
已知,a有重复项,b有重复项,这是正常的,但是a+b作为一个标示值的话不可以有重复项
如:a    b
   1    1
   1    2
   2    1
   1    1上面中的1   1
是重复的,我如何用语句把它找出来,
谢谢

解决方案 »

  1.   

    select distinct *
    from tb 
    group by a,b
    having count(*)>1
      

  2.   

    select a,b from 表 group by a,b having count(1)>1
      

  3.   

    select *
    from tb 
    group by a,b
    having count(*)>1
      

  4.   

    SELECT * FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE A=T.A AND B=T.B)
      

  5.   

    if OBJECT_ID('tb') is not null drop table tb
      create table tb(a int,b int)
      insert tb
    select  1,    1 
    union all select  1,    2 
    union all select    2,    1 
    union all select    1,    1 
    --查询所有不重复的数据
    select distinct * from tb
    /*
    a b
    1 1
    1 2
    2 1
    */--查询出那条数据重复
    select a,b from tb group by a,b having(COUNT(*)>1)
    /*
    a b
    1 1
    */
      

  6.   

    if OBJECT_ID('tb') is not null drop table tb
      create table tb(a int,b int)
      insert tb
    select  1,    1 
    union all select  1,    2 
    union all select    2,    1 
    union all select    1,    1 
    --查询所有不重复的数据
    select distinct * from tb
    /*
    a    b
    1    1
    1    2
    2    1
    */--查询出那条数据重复
    select a,b from tb group by a,b having(COUNT(*)>1)--2005
    select a, b from (select row_number() over(partition by a,b order by a,b) as id, a,b from tb) a where id > 1