数据库里字段如下
id  name  class  ...
现在我想查找库里name 和 class的重复数据,例如
1   李     2
2   李     2
3   李     3
4   李     5
查询后为
1   李     2
2   李     2
急求!!!!!!!!!

解决方案 »

  1.   


    select * from tb group by name,class having count(name)>1 and count(class)>1
      

  2.   

    select t1.* from [表名] t1,
    (select name,class from [表名] group by name,class having count(*)>1) t2
    where t1.name=t2.name and t1.class=t2.class
      

  3.   

     --参考思想:select * from tb where a2 in (select a2 from tb group by a2 having(count(*)>1))
      

  4.   

    select * from table where id in (select min(id) from table group by name, class)
      

  5.   


    select * from tb where name+','+Convert(nvarchar(10),class)=(select name+','+Convert(nvarchar(10),class) from tb group by name,class having count(*)>1)
      

  6.   

    select * from tb group by name,class having count(name)>1 and count(class)>1这个方法不错
      

  7.   


    这种写法再2000和2005里都会报错(因为还有id字段没在group中),2008我没验证过,有验证过的回复下。