SELECT DECODE(GROUPING(department_name), 1, 'All Departments',
      department_name) AS department_name,
   DECODE(GROUPING(job_id), 1, 'All Jobs', job_id) AS job_id,
   COUNT(*) "Total Empl", AVG(salary) * 12 "Average Sal"
   FROM employees e, departments d
   WHERE d.department_id = e.department_id
   GROUP BY CUBE (department_name, job_id)
   ORDER BY department_name, job_id;
---------------------------
SELECT DECODE(GROUPING(department_name), 1, 'All Departments', department_name) AS department_name
	, DECODE(GROUPING(job_id), 1, 'All Jobs', job_id) AS job_id
	, COUNT(*) AS "Total Empl"
	, AVG(salary) * 12 AS "Average Sal"
FROM employees e, departments d
WHERE d.department_id = e.department_id
GROUP BY CUBE (department_name, job_id)
ORDER BY department_name, job_id;

