2009年4月2日星期四

yearly salary budget rollup with 10g grouping function

thanks metaphysics for sharing this with me,
the function returns a value of 1 if the value of expr in the row is a null representing the set of all values.

SELECT

  DECODE(GROUPING(department_id), 1, '*', department_id) AS department,
  DECODE(GROUPING(job_id), 1, '*', job_id) AS job,
  COUNT(*) AS "Stuff", SUM(salary) * 12 AS "Yearly"
FROM hr.employees
GROUP BY ROLLUP (department_id, job_id)


Id_Operation Name RowsBytesCost (%CPU)Time
0_SELECT STATEMENT
10717124 (25)00:00:01
1__SORT GROUP BY ROLLUP
10717124 (25)00:00:01
2___TABLE ACCESS FULL EMPLOYEES 10717123 (0)00:00:01

NULLSA_REP184000
NULL*184000
10AD_ASST 152800
10*152800
20MK_MAN1 156000
20MK_REP172000
20*2228000
30PU_MAN1132000
30PU_CLERK5166800
30* 6298800
40HR_REP178000
40*1 78000
50ST_MAN5436800
50SH_CLERK20771600
50ST_CLERK20668400
50*451876800
60IT_PROG5345600
60*5345600
70PR_REP 1120000
70*1120000
80SA_MAN5 732000
80SA_REP292922000
80*343654000
90AD_VP2408000
90AD_PRES1288000
90*3696000
100FI_MGR1144000
100FI_ACCOUNT 5475200
100*6619200
110AC_MGR1 144000
110AC_ACCOUNT199600
110*2 243600
**1078296800

没有评论: