数据库表table,三个字段 a,b,c
我要找出所有有重复的记录比如
1 1  1
1 2 1
1 1 1
那么最后得到是1 1 1于是我使用如下方法DECLARE lcDuplicate CURSOR FOR
                SELECT DISTINCT T1.a,T1.b,T1.c
                FROM   table T1,
                (select a,b,c,count(*) DupNum from table
                 WHERE   //一些条件
                 GROUP  BY a,b,c) T2
                WHERE  T1.a= T2.a
                AND T1.b= T2.b
                AND T1.c= T2.c然后我用这个sql语句,能查出记录的,但是用了游标一旦FETCH lcDuplicate into @a,@b,@c得不到任何记录,上面的都是null
然后返回的是NO_MORE_ROWS_IN_CURSOR不知道什么原因了,是sql语句的原因吗
                AND T2.DupNum>1

解决方案 »

  1.   

    哦,上面的
    DECLARE lcDuplicate CURSOR FOR
                    SELECT DISTINCT T1.a,T1.b,T1.c
                    FROM   table T1,
                    (select a,b,c,count(*) DupNum from table
                     WHERE   //一些条件
                     GROUP  BY a,b,c) T2
                    WHERE  T1.a= T2.a
                    AND T1.b= T2.b
                    AND T1.c= T2.c
                    AND T2.DupNum>1少了最后一个条件
      

  2.   

    不知道是不是sql语句太复杂了??
    不知道大家有没有碰到过这个问题
      

  3.   

    select a,b,c from T group by a,b,c having count(*)>1  ???
      

  4.   

    create table t(a int,b int,c int)
    insert into t select 1,1,1
    insert into t select 1,2,1
    insert into t select 1,1,1
    insert into t select 1,3,1select a,b,c from t group by a,b,c having count(*) >1drop table t
    a           b           c           
    ----------- ----------- ----------- 
    1           1           1
      

  5.   

    你的SQL代码,尤其是你使用游标的代码问题