WITH
dept_costs AS (
SELECT d.department_name, Sum(salary) AS dept_total
FROM employees e, departments d
WHERE d.department_id = e.department_id
GROUP BY d.department_name ),
avg_cost AS (
SELECT Trunc (Sum(dept_total)*0.125) AS dept_avg
FROM dept_costs )
SELECT *
FROM dept_costs
WHERE dept_total >
(select dept_avg
FROM avg_cost)
ORDER BY department_name ;