Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 24 Write a SQL query that outputs the number of managers from each town.*/
- SELECT t.name AS town_name, COUNT(DISTINCT e.employee_id) AS managers_count
- FROM employees e
- JOIN addresses a ON e.address_id = a.address_id
- JOIN towns t ON a.town_id = t.town_id
- WHERE e.employee_id IN (SELECT DISTINCT manager_id FROM employees WHERE manager_id IS NOT NULL)
- GROUP BY t.name
- ORDER BY managers_count DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement