programming-examples/sql/SubqueriesHRDatabase/Write a query to display the department id and the total salary for those departments which contains at least one salaried employee.sql
2019-11-18 14:05:53 +01:00

11 lines
432 B
SQL

/*Write a query to display the department id and the total salary for those departments which contains at least one salaried
employee.
*/
SELECT departments.department_id, result1.total_amt
FROM departments,
( SELECT employees.department_id, SUM(employees.salary) total_amt
FROM employees
GROUP BY department_id) result1
WHERE result1.department_id = departments.department_id;