有一列 number类型 例如3 5 4 8 9 13 2 不重复
我想要知道5排第几位的sql怎么写
结果 5 第四位

解决方案 »

  1.   


    create table zzw_temp (num1 number);select * from zzw_temp for update;
    /*
    5
    3
    2
    13
    9
    8
    4
    */select rn from (
    select rownum rn,num1 from (
    select num1 from zzw_temp order by num1))
    where num1=5;drop table zzw_temp purge;
      

  2.   

    楼上 可以实现
    但是如果考虑到100万条以上记录的话 有没有不用多个select的更好的方法?
      

  3.   

    既然不重復,select count(*) from tb where id<=5 有多少記錄就是排第幾
      

  4.   

    order by 以后,取rownum