TheAnalyst / SQLAll lessons ↗
Day 11 · Aggregation & joins · 10–20 minutes

HAVING

WHERE filters input rows; HAVING filters groups after aggregation.

01 · Learn

The idea

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;
Read it actively

Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.

02 · Recall

Explain it without looking

In your own words, explain the main SQL feature in today’s lesson and why it answers the question.

03 · Solve

Run your own query

Show customers whose total order value exceeds 2500.

Loading browser SQL engine…
04 · Repeat

Close the loop