DataBolt

SQL LEARNING PLATFORM

9

CHAPTER 9

GROUP BY

Aggregating by category — the analytics workhorse.

3

Learning Blocks

SQL

Interactive Queries

In This Chapter

Concepts you'll master

1

How GROUP BY splits data into buckets before aggregating

2

Grouping by a single column

3

Grouping by multiple columns

4

Combining GROUP BY with WHERE

🌟 Think of it this way: GROUP BY is like sorting coins into labelled bags — all 1-rupee coins into one bag, all 5-rupee into another — and then counting each bag separately. Each bag becomes one row in your result.

11.1 - Employees Department

SQL QUERY
SELECT department, COUNT(*) AS headcount, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
ORDER BY avg_salary DESC;

Exercise

Practice your SQL skills

SQL EDITOR
Press semicolon (;) to auto-run query

Tasks

Complete all SQL challenges

1

Find the number of employees in each department.

Current Task
2

Find the total salary of each department.

3

Find the average salary of each department.

4

Find the minimum and maximum salary in each department.

Need help solving this task?