oracle统计各类数据(ratio_to_report函数,计算比例)

--统计图(比例大于5,统计各类,比例小于5的则汇总统计值)

select * from (
select name,
       sum(rs) as rs,
        round(ratio_to_report(sum(rs)) over(), 5) * 100   as bl
  from (select  *from test) a
 group by name 
)
where bl>=5
 
 union all
 select '其他',sum(rs),sum(bl) from (
select name,
       sum(rs) as rs,
        round(ratio_to_report(sum(rs)) over(), 5) * 100   as bl
  from (select * from test) a
 group by name 
)
where bl<5

你可能感兴趣的:(oracle)