如何查询出一个表中某些字段相同的那些记录??比如 class 表中  有 id name age sex address 这几个字段   如何查处名字 年龄 性别都相同的记录????
请高手指教! 

解决方案 »

  1.   

    select * from class
    group by (name,age,sex);
      

  2.   

    这个你首先要确定这几个字段的类型是一样的select * from class c where c.name=c.age and c.age=c.sex;这样就可以了!
      

  3.   

    先按这三个属性分组,根据count()>1来找出所有有重复的数据,  再拿原来的表与这子表相关联就可以了  
      

  4.   

    select *
    from class t
    where (select count(1) from class where name=t.name and age=t.age and sex=t.sex)>1
      

  5.   

    或者select a.*
    from class a
    join (select name,age,sex from class group by name,age,sex having count(1)>1)b
    on a.name=b.name and a.age=b.age and a.sex=b.sex
      

  6.   

    select * from class group by name,sex,age having count(*)>1
      

  7.   

    select name,age,sex from class group by name,age,sex having count(1)>1
      

  8.   

    group by后面的字段一定要在前面的列表项里面出现。
    8楼正解
      

  9.   

    select id,count(*) ci from  class group by(name,age,sex) order by ci desc