How do I find the minimum and maximum unit price per customer in SQL?
SELECT customer, MIN(unit_price) AS min_price, MAX(unit_price) AS max_price
FROM data
GROUP BY customer
ORDER BY customer;
Run this query in QueryLocal →
`MIN()` and `MAX()` can be computed in the same query, both scoped by the same `GROUP BY customer` — SQL doesn't limit you to a single aggregate function per query, as long as every non-aggregated column in the SELECT list also appears in the `GROUP BY`.
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).