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 finding the total sales per product.
Click to reveal answer
beginner
How do you use
GROUP BY with a single column?You list one column after
GROUP BY to group rows by that column's values. For example, GROUP BY department groups all rows by each department.Click to reveal answer
intermediate
How does
GROUP BY work with multiple columns?You list multiple columns separated by commas after
GROUP BY. This groups rows by unique combinations of those columns. For example, GROUP BY city, department groups rows by each city and department pair.Click to reveal answer
beginner
Why do you often use aggregate functions with
GROUP BY?Because
GROUP BY creates groups, aggregate functions like SUM(), COUNT(), or AVG() calculate summary values for each group.Click to reveal answer
intermediate
What happens if you select columns not in the
GROUP BY clause or aggregate functions?PostgreSQL will give an error because every selected column must be either grouped or aggregated to avoid confusion about which row's value to show.
Click to reveal answer
What does
GROUP BY department do?✗ Incorrect
GROUP BY department groups rows that share the same department value into one group.
Which query groups by both city and department?
✗ Incorrect
Use commas to list multiple columns in GROUP BY, like GROUP BY city, department.
Which aggregate function counts rows in each group?
✗ Incorrect
COUNT() counts the number of rows in each group.
What error occurs if you select a column not in
GROUP BY or aggregated?✗ Incorrect
PostgreSQL requires all selected columns to be grouped or aggregated to avoid ambiguity.
What is the result of
GROUP BY?✗ Incorrect
GROUP BY groups rows into summary rows based on column values.
Explain how to use
GROUP BY with one and multiple columns in PostgreSQL.Think about grouping by one column versus grouping by pairs or more.
You got /4 concepts.
Why must columns in SELECT be either in
GROUP BY or aggregated?Consider what happens if you select a column not grouped or aggregated.
You got /4 concepts.