>_ QueryLocal All recipes
SQL recipe

How do I keep only groups whose total exceeds 300 using SQL HAVING?

SELECT category, SUM(quantity * unit_price) AS revenue
FROM data
GROUP BY category
HAVING SUM(quantity * unit_price) > 300
ORDER BY revenue DESC;
Run this query in QueryLocal →

`HAVING` filters groups after aggregation, unlike `WHERE` which filters rows before it. Here only category groups whose summed revenue is above 300 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).