比如有一张工人信息的表gongrenxinxi,里面有一个包含工资的字段gongzi,将工资按降序排列,找出工资位于95%的人的工人信息

解决方案 »

  1.   

    count算出总人数,再乘0.95,取整,这个数字就是95分位数,再将表order by 排序,用rownum读出这条记录。
      

  2.   

    刚在网上搜了一下,工资的95分位数不是这么算的,很复杂。我这是之前工时分析用的,看来不一样。
    我想了想,应该是先对数据集进行排序,排序后再用row_num()进行编号,然后再用count(*)*0.5取整,使其与行号相等,读出这条记录
      

  3.   

    一张起终点表,包含了不同人不同路径的许多数据,现在针对某一条起点i,终点j 的路径,对他的出行时间进行升序排序然后编号,想要求出编号位置位于全部编号的95%的出行时间,其求95分位数出行时间,程序如下,出现
    FUNCTION TH95_TRAVEL_TIME 已编译
    Errors: check compiler log  的错误,本人初学者,求大神解答疑惑,create or replace function th95_travel_time(i number,j number)
    return number
    as
    begin 
       declare cursor cu_travel_time is
       select row_number() over (order by 出行时间) rn,出行时间 from 起终点表 where 地点A=i and 地点B=j;
       row_number 起终点表.rn%type;
       travel_time 起终点表.出行时间%type;
       travel_time_95th 起终点表.出行时间%type;
       odjilu 起终点表.rn%type; 
       
       begin
          select count(*)  into odjilu from 起终点表 where 地点A=i and 地点B=j;    --将查询到的记录数目赋值给odjilu
          open cu_travel_time;
          fetch cu_travel_time into row_num,travel_time;
          
          loop
            if row_num=round(odjiuli*0.95,0) then
               travel_time_95th:=travel_time;
               exit;
            end if;
            
            fetch cu_travel_time into row_num,travel_time;
            
          end loop;
          close cu_travel_time;
          
          return travel_time_95th;
       end;
    end  th95_travel_time; 
      

  4.   

    SELECT percentile_cont(0.95) within GROUP( ORDER BY 工资) as p95 from  表