Aggregate Queries (16–30)
- Count total employees
SELECT COUNT(*) FROM Employee;
- Count employees in HR
SELECT COUNT(*) FROM Employee WHERE department = 'HR';
- Find total salary payout
SELECT SUM(salary) FROM Employee;
- Find average salary
SELECT AVG(salary) FROM Employee;
- Find highest salary
SELECT MAX(salary) FROM Employee;
- Find lowest salary
SELECT MIN(salary) FROM Employee;
- Count employees by department
SELECT department, COUNT(*) FROM Employee GROUP BY department;
- Find avg salary by department
SELECT department, AVG(salary) FROM Employee GROUP BY department;
- Find highest salary by department
SELECT department, MAX(salary) FROM Employee GROUP BY department;
- Find departments with more than 5 employees
SELECT department, COUNT(*)
FROM Employee
GROUP BY department
HAVING COUNT(*) > 5;
- Find departments with avg salary > 60000
SELECT department, AVG(salary)
FROM Employee
GROUP BY department
HAVING AVG(salary) > 60000;
- Count distinct departments
SELECT COUNT(DISTINCT department) FROM Employee;
- Find total salary by department
SELECT department, SUM(salary) FROM Employee GROUP BY department;
- Find total employees in each location
SELECT location, COUNT(*) FROM Employee GROUP BY location;
- Find max salary where department = IT
SELECT MAX(salary) FROM Employee WHERE department = 'IT';