# Lesson 5: GROUP BY and aggregates GROUP BY and aggregates comes up in almost every real SQL project. We start with the why, then write code together. Full lesson: [https://glibcode.net/courses/sql-essentials/lessons/5](https://glibcode.net/courses/sql-essentials/lessons/5) ## Files - `group_by.sql`: aggregates per group and HAVING > **Tip:** Count before you delete: run the same WHERE with `SELECT COUNT(*)` first. ## Run it ```sh sqlite3 shop.db < ../../setup/schema.sql sqlite3 shop.db < ../../setup/seed.sql sqlite3 shop.db < group_by.sql ``` ## Exercises See [exercises.md](exercises.md). Ask in the forum after you have tried.