Recall & Review
beginner
What does the
GROUP BY clause do in SQL?It groups rows that have the same values in specified columns into summary rows, like grouping all sales by each product.
Click to reveal answer
beginner
How do you use
GROUP BY with multiple columns?You list the columns separated by commas after
GROUP BY. This groups rows by unique combinations of those columns.Click to reveal answer
intermediate
Why would you group by multiple columns instead of just one?
Grouping by multiple columns lets you see detailed summaries for each unique combination, like sales by product and region together.
Click to reveal answer
beginner
Example: What does this query do?<br>
SELECT city, department, COUNT(*) FROM employees GROUP BY city, department;
It counts how many employees work in each department within each city, grouping by both city and department.
Click to reveal answer
intermediate
Can you use
ORDER BY with GROUP BY on multiple columns?Yes, you can order the grouped results by one or more columns to sort the summary rows as you want.
Click to reveal answer
What happens if you use
GROUP BY city, department in a query?✗ Incorrect
Using multiple columns in GROUP BY groups rows by each unique combination of those columns.
Which SQL clause is used to summarize data by groups?
✗ Incorrect
GROUP BY groups rows to allow aggregation functions like COUNT or SUM on each group.
If you want to count employees per city and department, which is correct?
✗ Incorrect
Grouping by both city and department counts employees for each unique city-department pair.
Can you use aggregate functions like COUNT() with GROUP BY multiple columns?
✗ Incorrect
Aggregate functions summarize data within each group defined by GROUP BY.
What does this query return?<br>
SELECT product, region, SUM(sales) FROM sales_data GROUP BY product, region;
✗ Incorrect
The query sums sales grouped by each product and region pair.
Explain how
GROUP BY with multiple columns works and why it is useful.Think about grouping data like sorting mail by city and street together.
You got /3 concepts.
Write a simple SQL query using
GROUP BY with two columns and explain what it does.Use example like counting employees by city and department.
You got /3 concepts.