How do I keep only groups whose total exceeds 100 using SQL HAVING?
SELECT customer, SUM(quantity * unit_price) AS revenue
FROM data
GROUP BY customer
HAVING SUM(quantity * unit_price) > 100
ORDER BY revenue DESC;
Run this query in QueryLocal →
`HAVING` filters groups after aggregation, unlike `WHERE` which filters rows before it. Here only customer groups whose summed revenue is above 100 survive — the threshold and grouping column can both change without touching the underlying pattern.
A table named data with columns: order_id (integer), customer (text), country (text), category (text), quantity (integer), unit_price (real), order_date (text, YYYY-MM-DD).