SELECT manager_id, first_name, last_name, COUNT(employee_id) direct_reports FROM employees WHERE manager_id IS NOT NULL GROUP BY manager_id;
SELECT manager_id, first_name, last_name, COUNT(employee_id) direct_reports FROM employees WHERE manager_id IS NOT NULL GROUP BY manager_id HAVING direct_reports >= 5;
SELECT department_id, SUM(salary) FROM employees GROUP BY department_id HAVING SUM(salary) BETWEEN 20000 AND 30000 ORDER BY SUM(salary);
SELECT e.department_id, department_name, MIN(salary) FROM employees e INNER JOIN departments d ON d.department_id = e.department_id GROUP BY e.department_id HAVING MIN(salary) >= 10000 ORDER BY MIN(salary);
SELECT e.department_id, department_name, ROUND(AVG(salary), 2) FROM employees e INNER JOIN departments d ON d.department_id = e.department_id GROUP BY e.department_id HAVING AVG(salary) BETWEEN 5000 AND 7000 ORDER BY AVG(salary);