select [NO]
       ,(select count(1) 
            from 表 
               where a=t.a 
                      and b=t.b 
                      and c=t.c
        ) as 'count'
from 表 t
where exists(select 1 
               from 表 
                  where a=t.a
                        and b=t.b 
                        and c=t.c 
                        and [NO]<>t.[NO])

解决方案 »

  1.   

    select [NO]
           ,(select count(1) 
                from 表 
                   where a=t.a 
                          and b=t.b 
                          and c=t.c
            ) as 'count'
    from 表 t
    where exists(select 1 
                   from 表 
                      where a=t.a
                            and b=t.b 
                            and c=t.c 
                            and [NO]<>t.[NO])
    order by a,b,c
      

  2.   

    万分感谢!!!如果我的表有30个字段,3万条记录。我想求出依次去掉一个字段再来求出重复的行(结果集要求跟上面一样),是不是可以做成存储过程。在程序里循环调用这个存储过程.
    这个存储过程应该怎么写?还是直接调用select语句就可以,不用存储过程
      

  3.   

    select a.no,b.countnum from table_name a, 
    (select a,b,c,count(*) as countnum from table_name group by a,b,c having count(*) >1 ) b
    where a.a = b.a and a.b= b.b and a.c = b.c 
    order by b.countnum,a.no
      

  4.   

    select a.no,b.count from 
     biao a,(select a,b,c,count(*) as count from biao group by a,b,c) b
    where a.a=b.a and a.b=b.b and a.c=b.c