Debug SQL in layers: joins, filters, grouping, and sorting.
Debug SQL in layers: joins, filters, grouping, and sorting. Predict the output before running the example.
SELECT c.name,SUM(o.amount) AS revenue FROM customers c JOIN orders o ON o.customer_id=c.customer_id WHERE o.amount>0 GROUP BY c.customer_id,c.name HAVING SUM(o.amount)>2000 ORDER BY revenue DESC;
What does today's SQL feature do, and when would you use it?
WHERE filters rows before grouping; HAVING filters groups after.
Run the example, then modify one clause and predict how the result changes.
WHERE filters rows before grouping; HAVING filters groups after.