How do I compute the average unit price per customer in SQL?
SELECT customer, AVG(unit_price) AS avg_price
FROM data
GROUP BY customer
ORDER BY avg_price DESC;
Run this query in QueryLocal →
`AVG(unit_price)` computed after `GROUP BY customer` gives the mean unit price within each customer, not across the whole table. This is the aggregate-function-plus-GROUP-BY pattern applied to a different grouping column and a different metric.
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).