>_ QueryLocal All recipes
SQL recipe

How do I total revenue for each category with SQL?

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

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