My code below is duplicating my department name results and I don't know why. I need to display the name of the department, job id for the employees who work there and their salary. Plus I need to figure out if department\_id or job\_id was used in the CUBE expression.

```
SELECT d.department_name AS "Name", 
       e.job_id AS "Job ID", 
       SUM(e.salary) AS "salary", 
       DECODE(GROUPING(d.department_id),1, 'Yes', 'No') AS "Department Used", 
       DECODE(GROUPING(e.job_id), 1, 'Yes', 'No') AS "Job used"
FROM employees e 
    full OUTER JOIN departments d 
    ON (e.department_id = d.department_id)
GROUP BY CUBE(d.department_name, e.job_id, d.department_id)
ORDER BY d.department_name;

```

[![Results](https://i.stack.imgur.com/lez4L.png)](https://i.stack.imgur.com/lez4L.png)