MicrolearnENPTES

GROUP BY

Lesson 11 of 24 · SQL.Micro

GROUP BY splits the rows into groups and runs the aggregate once per group, producing one row per group.

SELECT category, COUNT(*) FROM products GROUP BY category;

Every non-aggregated column in SELECT should appear in GROUP BY.

You can group by several columns: GROUP BY country, city.

Check yourself

How many rows does GROUP BY country return?

Show each category and how many products it has.

Do it in the browser: a real SQL tool, a short mission and instant feedback. No install.

Start this lesson — free
← SUM, AVG, MIN and MAXFiltering groups with HAVING →

All lessons · SQL.Micro