某表中有一列a
查詢a是否有重複數據,怎麼查詢?

解决方案 »

  1.   

    select a,count(*) from table group by a having count(*)>1如果能查出来就是有重复记录
      

  2.   


    SQL> select deptno,count(deptno) from scott.emp
      2  having count(deptno)>0
      3  group by deptno;DEPTNO COUNT(DEPTNO)
    ------ -------------
        10             3
        20             5
        30             6
      

  3.   


    with t as (
    select 1 num from dual
    union all
    select 3 from dual
    union all
    select 3 from dual
    union all
    select -1 from dual
    union all
    select 2 from dual
    )select decode(count(num)-count(distinct num),0,'不存在重复','存在重复') from t
    存在重复