How do I bucket orders as bulk vs single at a quantity threshold of 3 in SQL?
SELECT
CASE WHEN quantity >= 3 THEN 'bulk' ELSE 'single' END AS order_size,
COUNT(*) AS orders,
SUM(quantity * unit_price) AS revenue
FROM data
GROUP BY order_size;
Run this query in QueryLocal →
Moving the threshold in `CASE WHEN quantity >= 3` changes where the split between "bulk" and "single" falls, without changing the shape of the query — the bucketed label still becomes a group-able column exactly like a real one.
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).