Module 03
Grouping & Business KPIs
Aggregate transactional rows into analytical dashboards and isolate specific group sectors cleanly.
📋 Source Dataset (4 Sample Records)
| name | department | salary | city |
|---|---|---|---|
| Amit | Tech | 80000 | Noida |
| Rohan | HR | 55000 | Mumbai |
| Neha | Tech | 90000 | Noida |
| Vikram | HR | 60000 | Noida |
1. COUNT & AVG Functions
Definition: COUNT tallies total logged profiles while AVG calculates the numerical mathematical mean within grouped segments.
SELECT department, COUNT(*) AS emp_count, AVG(salary) AS avg_sal FROM employees GROUP BY department;
| department | emp_count | avg_sal |
|---|---|---|
| Tech | 2 | 85000 |
| HR | 2 | 57500 |
2. SUM & MAX Aggregations
Definition: SUM calculates full financial expense pipelines, while MAX extracts peak values per sector group.
SELECT city, SUM(salary) AS total_budget, MAX(salary) AS max_sal FROM employees GROUP BY city;
| city | total_budget | max_sal |
|---|---|---|
| Noida | 230000 | 90000 |
| Mumbai | 55000 | 55000 |
3. HAVING Filter Clause
Definition: Evaluates filter logic strictly after aggregation groups are built (since WHERE cannot handle summary functions).
SELECT department, AVG(salary) AS average_salary FROM employees GROUP BY department HAVING AVG(salary) > 70000;
| department | average_salary |
|---|---|
| Tech | 85000 |
Unlock Real Corporate Scenario Interactive Sandboxes
Basic structures are covered! To clear FAANG, MAANG & top analytical enterprise interviews, buy the complete pack to get 150+ interactive practice question sheets, video explanation keys, and real production datasets.