>_ QueryLocal All recipes
SQL recipe

How do I total revenue for each customer with SQL?

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

Same pattern as grouping by any other column: `GROUP BY customer` buckets rows that share the same customer, and `SUM(quantity * unit_price)` totals each bucket's revenue independently. Sorting by `revenue DESC` puts the highest-earning customer first.

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).