5 questions to test your understanding
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?
Consider: SELECT region, sales_rep, SUM(amount) FROM sales GROUP BY region. What is wrong with this query?
The HAVING clause is evaluated after grouping is complete, which is why it can reference aggregate functions like SUM() and COUNT().
COUNT(*) and COUNT(column_name) usually return the same result when applied to the same table.
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.