You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 lines
492 B
SQL

/*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;