现有一个表 表里有某个字段(是一些数字,从1到10000都有,很多是重复的),现要把该字段下相同的数字共等于13个的查询并显示出来。一个一个去查找是可以找到,但由于数据量巨大,虽用到循环语句,请问该循环语句如何写?(本人所用软件为SI object borwser)

解决方案 »

  1.   

    为什么要用循环语句,你只是要显示有重复的信息,用下面类似的语句不行?
    select *
    from test_table t1
    where exists(select 1
                            from test_table t2
                            where t1.id=t2.id
                            group by t2.id 
                            having count(*)>1)
      

  2.   

    select  * from table  t1 where  sum(case when (select 1 from table t2 where t1.id=t2.id) is not null then 1
    else
    0
    end)=13
      

  3.   

    select *
    from test_table t1
    where exists(select 1
                            from test_table t2
                            where t1.id=t2.id
                            group by t2.id 
                            having count(*)=13)
    这样也不行?
      

  4.   

    Select * from t a where  exists(select 1 from (
    select c.aa from t group by t.aa having sum(1)=13) b
    where a.aa=b.aa)
      

  5.   

    研究一下 OVER(PARTITION BY) ,这个绝对能做出来