获得该表的60%的行

时间:2013-05-09 11:02:13

标签: sql oracle

我想在Oracle的60%表中选择行。我可以通过以下方式找到60%行的编号:

select round(count(*)*0.60) as sira from 
    (select to_date(time) as tarih,lenght as hiz  from table order by length desc)

我正在寻找60%的行的名称列数据。也就是说,所有行的60%应该具有比所选行更长的长度。

例如,对于此数据:

name   time    length
r1     10:00   1
r2     10:02   2
r3     10:04   3
...
r10    10:20   10

我正在寻找打印r4的查询(通过减少长度来排序60%的行。)

1 个答案:

答案 0 :(得分:2)

select  *
from    (
        select  row_number() over (order by yt.length desc) as rn
        ,       count(*) over () as cnt
        ,       yt.*
        from    YourTable yt
        ) SubQueryAlias
where   rn = round(cnt * 0.60)

Example at SQL Fiddle.