WHERE filters input rows; HAVING filters groups after aggregation.
WHERE filters input rows; HAVING filters groups after aggregation. Read the query line by line and identify the input table, the transformation, and the shape of the result before running it.
SELECT customer_id, SUM(amount) AS total_revenue FROM orders GROUP BY customer_id HAVING SUM(amount) > 2500 ORDER BY total_revenue DESC;
Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.
In your own words, explain the main SQL feature in today’s lesson and why it answers the question.
Recall prompt: Add HAVING SUM(amount) > 2500 after GROUP BY. Close this page section mentally and explain the query from memory before proceeding.
Show customers whose total order value exceeds 2500.
Add HAVING SUM(amount) > 2500 after GROUP BY.