Questions: SQL Aggregation and GROUP BY

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A database has an 'orders' table with columns customer_id, order_date, and amount. You want to show only customers who have placed more than 5 orders total. Where does this filter belong?

AIn a WHERE clause: WHERE COUNT(order_id) > 5
BIn a HAVING clause: HAVING COUNT(*) > 5, after GROUP BY customer_id
CIn a WHERE clause: WHERE order_count > 5, since WHERE runs after aggregation
DEither WHERE or HAVING work — they filter at different stages but produce identical results
Question 2 Multiple Choice

Consider: SELECT region, sales_rep, SUM(amount) FROM sales GROUP BY region. What is wrong with this query?

ASUM(amount) is wrong — you should use AVG(amount) when grouping by region
BNothing — this is a valid query that groups by region and shows each sales rep's contribution
Csales_rep appears in SELECT but not in GROUP BY and is not aggregated — this is a SQL error
DYou need a HAVING clause whenever you use GROUP BY
Question 3 True / False

The HAVING clause is evaluated after grouping is complete, which is why it can reference aggregate functions like SUM() and COUNT().

TTrue
FFalse
Question 4 True / False

COUNT(*) and COUNT(column_name) usually return the same result when applied to the same table.

TTrue
FFalse
Question 5 Short Answer

Explain why the distinction between WHERE and HAVING depends on *when* each clause is evaluated in query execution, and give an example of a filter that belongs in each.

Think about your answer, then reveal below.