SELECT HOME_DEPT, LINECODE, SUM(TOTAL_HRS),
TO_CHAR (
100*RATIO_TO_REPORT(SUM(TOTAL_HRS))
OVER (PARTITION BY HOME_DEPT),
'990.00L', 'NLS_CURRENCY=%'
) PCT_JOB
FROM TABLE
GROUP BY HOME_DEPT, LINECODE ORDER BY HOME_DEPT ASC, PCT_JOB DESC;
The above Oracle query works and produces results as such:
DEPT1 LINECODE1 100 50%
DEPT1 LINECODE2 50 25%
DEPT1 LINECODE3 50 25%
DEPT2 LINECODE1 20 12.5%
DEPT2 LINECODE2 20 12.5%
DEPT2 LINECODE3 20 12.5%
DEPT2 LINECODE4 20 12.5%
DEPT2 LINECODE5 20 12.5%
DEPT2 LINECODE6 20 12.5%
DEPT2 LINECODE7 20 12.5%
DEPT2 LINECODE8 20 12.5%
now I want to rollup per department to get results as such:
DEPT1 LINECODE1 100 50%
DEPT1 LINECODE2 50 25%
DEPT1 LINECODE3 50 25%
DEPT1 200 100% <--- desired
DEPT2 LINECODE1 20 12.5%
DEPT2 LINECODE2 20 12.5%
DEPT2 LINECODE3 20 12.5%
DEPT2 LINECODE4 20 12.5%
DEPT2 LINECODE5 20 12.5%
DEPT2 LINECODE6 20 12.5%
DEPT2 LINECODE7 20 12.5%
DEPT2 LINECODE8 20 12.5%
DEPT2 160 100.0% <--- desired
I have tried various things such as GROUPING SETS but then my PCT_JOB values are wrong.