What does GROUP BY do?
Model answer
It groups rows that have the same values in the given columns so you can aggregate each group: SELECT city, COUNT(*) FROM customers GROUP BY city. Every selected column must either be in GROUP BY or inside an aggregate function.
Learn this topic
GROUP BY and HAVING: Summaries for Each Group in the course SQL for Beginners: Learn Databases Step by Step.
Sign in to add your own answer.
More questions
- What are aggregate functions?
- What is the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column)?
- How do you find duplicate values in a column?
- What does HAVING do?
- How do you count rows per category including categories with zero rows?
- How do you calculate a running total or percentage of total?