計算百分比-比例函數ratio_to_report

select no as 部門,

                     工資合計,

                     總合計,

                     round((工資合計/總合計)*100,2) as 工資比列

from (select no,工資合計,sum(工資合計) over() as 總合計

          from (select no,sum(sal) 工資合計 from tab1 group by deptno) x) y

order by 1;

也可以用專門比例函數ratio_to_report

select no,round(ratio_to_report(工資合計) over()*100,2) as 工資比例

from (select no,sum(sal) 工資合計 from emp group by no)

order by 1;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章