programming-examples/sql/JoinHRDatabase/21. Write a query in SQL to display the country name, city, and number of those departments where at leaste 2 employees are working.sql

12 lines
492 B
MySQL
Raw Normal View History

2019-11-18 14:05:53 +01:00
/*21. Write a query in SQL to display the country name, city, and number of those departments where at leaste 2 employees
are working.*/
SELECT country_name,city, COUNT(department_id)
FROM countries
JOIN locations USING (country_id)
JOIN departments USING (location_id)
WHERE department_id IN
(SELECT department_id
FROM employees
GROUP BY department_id
HAVING COUNT(department_id)>=2)
GROUP BY country_name,city;