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

11 lines
432 B
MySQL
Raw Normal View History

2019-11-18 14:05:53 +01:00
/*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;