How do I sort by category and then by value (ASC) in SQL?
SELECT category, quantity * unit_price AS line_total
FROM data
ORDER BY category ASC, line_total DESC;
Run this query in QueryLocal →
Multi-column `ORDER BY` sorts first by category (ASC), and only breaks ties on that column using `line_total DESC` as the second key — the same tie-breaking logic as sorting a spreadsheet by two columns at once.
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).