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

发布了14 篇原创文章 · 获赞 0 · 访问量 6683

猜你喜欢

转载自blog.csdn.net/Anry_2018/article/details/91981415