一张表tab有三个字段a、b、c,我想检索出a和b的字段分别重复而c字段不重复的所有纪录,该如何写SQL语句呢?

解决方案 »

  1.   

    select * from tab
    where (a,b) in (
    select a,b 
    from tab
    group by a,b
    having count(distinct c)>1
    )
      

  2.   

    意思是:
    a   b    c
    1   1    1
    1   1    2
    1   1    2
    结果
    a   b    c
    1   1    1
    1   1    2
    select a,b,c from tab
    group by a,b
    直接group by 就可以了
      

  3.   

    如果这样的话,直接
    select distinct a,b,c from tab 不就行了?况且楼上那样写也不对啊!select a,b,c from tab
    group by a,b,c