有个表,结构如:            a      b      c
                        dfgh    233    1.6
                        dfgh    234    3.0
                        pole    233    5.1
                        pole    233    2.3
                        ....    ...    ...
把表中a相同且b相同的重复记录查询出来,如  pole  233  5.1       pole 233  2.3 

解决方案 »

  1.   

    select 
      *
    from
      tb t
    where
      (select count(1) from tb where a=t.a and b=t.b)>1
      

  2.   

    select * from tb a,(select a,b from tb group by a,b having count(*)>1)b
    where a.a=b.a and a.b=b.b
      

  3.   

    select  *
    from tb k
    where exists (select 1 from tb where a=k.a and b=k.b group by a,b having count(1)>1)
      

  4.   

    select  *
    from tb k
    where exists (select 1 from tb where a=k.a and b=k.b and k.c<>c)
      

  5.   

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

  6.   

      ResultSet set = smt.executeQuery("select DISTINCT a.[本厂编号],a.[参数值],a.[参数描述] from [镀金板电镀面积$] a where (select count(1) from a where [本厂编号]=a.[本厂编号] and [参数值]=a.[参数值])>1");java.sql.SQLException: [Microsoft][ODBC Excel Driver] Microsoft Jet 数据库引擎找不到对象'a'。请确定对象是否存在,并正确地写出它的名称和路径。难道在EXCEL中不能这样用的吗? 1楼的的答案我不太懂,但把a该为[镀金板电镀面积$],它把dfgh    233    1.6   dfgh    234    3.0  这些数据都读了出来,究竟哪里出了问题?   
      

  7.   


    select DISTINCT [本厂编号],[参数值],[参数描述] from [镀金板电镀面积] a where (select count(1) from [镀金板电镀面积] where [本厂编号]=a.[本厂编号] and [参数值]=a.[参数值])>1应该这样写, 试试~
      

  8.   

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

  9.   

    select * from tb a,
    (select a,b from tb group by a,b having count(*)>1)b
    where a.a=b.a and a.b=b.b
      

  10.   

    我上面的回复是9楼的查询语句,11楼的count(a)>1,是达不到我要的结果的,因为板是两面的,它都是一个编号!
      

  11.   

    create table tbtest( a  varchar(10),    b    int,   c decimal(18,2))
    insert tbtest
    select                        'dfgh'  ,  233  ,  1.6 union 
    select                        'dfgh'  ,  234  ,  3.0 union
    select                        'pole'  ,  233  ,  5.1 union
    select                        'pole'  ,  233  ,  2.3--drop table tbtestSELECT * FROM tbtest T WHERE EXISTS(SELECT 1 FROM tbtest WHERE A=T.A AND B=T.B AND C<>T.C)
    a          b           c                    
    ---------- ----------- -------------------- 
    pole       233         2.30
    pole       233         5.10(所影响的行数为 2 行)
      

  12.   


    select DISTINCT a.[本厂编号],a.[参数值],a.[参数描述] from [镀金板电镀面积$] 
    你的那个表名 as  a where (select count(1) from a where [本厂编号]=a.[本厂编号] and [参数值]=a.[参数值])>1
      

  13.   

    select * from tbtest s where  (select count(1) from tbtest where a=s.a and b=s.b)>1
      

  14.   

    select a.a,a.b,a.c from tbtest a,(select a,b from tbtest group by a,b having count(*)>1)b
    where a.a=b.a and a.b=b.b
      

  15.   

     ResultSet set = smt.executeQuery(" select * from [镀金板电镀面积$] a,(select[本厂编号],[参数值] from [镀金板电镀面积$] group by [本厂编号],[参数值] having count(*)>1)b where a.[本厂编号]=b.[本厂编号] and a.[参数值]=b.[参数值]");
     
    部分结果22I23GP 233  4.26
           22I23GP 234  2.92 
           32I23GP1 233  3.83
           32I23GP1 233  4.26 
           32I23GP1 234  2.5 
           32I23GP1 234  2.92 
           32J4HAP 233  3.94 
           32J4HAP 234  8.94 
    我想要的是红色部分的数据,怎么连其他的那些数据也查询出来了?
      

  16.   

    请教一下各位大虾:
    select * from tb a,(select a,b from tb group by a,b having count(*)>1)b
    where a.a=b.a and a.b=b.b中的select a,b from tb group by a,b having count(*)>1它是得出a字段或b字段重复的记录,还是得出一个结果集,该集中的记录的a与b与下一条记录中的a与b分别相等/????
      

  17.   

    SQL77你的答案可以,可能是我的机子太差,查起来好慢!
      

  18.   

    采用自连接的方式
    select distinct m.* from t_table m join t_table n on m.id!=n.id and m.a=n.a and m.b=n.b
     这样就OK了!
      

  19.   

    select * from 表 as a
    where (select count(*) from 表 where a=a.a and b=a.b)>1
      

  20.   

    环境:winXPsp3,5000+,2G内存,sql2k和05一样(其他各位的没有测试)
      

  21.   


    你的语句有漏洞的
    如果数据是
    a    b   c

    dfgh 233,1.6
    pole 233,1.3
    pole 233,2.3
    你的语句不该考虑C字段,楼主也没说C字段作为条件