「DB2 小計と合計と割合」の版間の差分
ナビゲーションに移動
検索に移動
| 1行目: | 1行目: | ||
| − | ==DB2 小計と合計と割合== | + | ==[[DB2 小計と合計と割合]]== |
| − | [[DB2]] | [[Database]] | | + | [[DB2]] | [[Database]] | [[Category:SQL]] |
{{amazon|4873113156}} | {{amazon|4873113156}} | ||
| − | ====SUM | + | ====SUM OVE[[R]]==== |
select workdept, dept_total, total, (dept_total * 100.00 / total) as pct from( | select workdept, dept_total, total, (dept_total * 100.00 / total) as pct from( | ||
select distinct | select distinct | ||
| 14行目: | 14行目: | ||
order by workdept | order by workdept | ||
=====結果===== | =====結果===== | ||
| − | WORKDEPT DEPT_TOTAL TOTAL | + | WORKDEPT DEPT_TOTAL TOTAL [[PC]]T |
-------- ---------- ---------- ----- | -------- ---------- ---------- ----- | ||
A00 354250.00 2442525.00 14.50 | A00 354250.00 2442525.00 14.50 | ||
2020年2月16日 (日) 04:24時点における最新版
DB2 小計と合計と割合
SUM OVER
select workdept, dept_total, total, (dept_total * 100.00 / total) as pct from( select distinct workdept, sum(salary) over(partition by workdept) as dept_total, sum(salary) over() total from employee ) order by workdept
結果
WORKDEPT DEPT_TOTAL TOTAL PCT -------- ---------- ---------- ----- A00 354250.00 2442525.00 14.50 B01 94250.00 2442525.00 3.85 C01 308890.00 2442525.00 12.64 D11 646620.00 2442525.00 26.47 D21 358680.00 2442525.00 14.68 E01 80175.00 2442525.00 3.28 E11 317140.00 2442525.00 12.98 E21 282520.00 2442525.00 11.56
© 2006 矢木浩人