Report with a Grand Total Row

medium
Unit 19 · Union0/2 to milestone

Finance wants a report with a TOTAL line at the bottom. Return country and revenue for each country with orders, sorted by revenue (highest first), followed by one final row with country = 'TOTAL' and the overall revenue.

SQLite has no ROLLUP, so combine two queries with UNION ALL, and make sure the total row sorts last.

Schema

customers(id, name, country, signup_date)
orders(id, customer_id, order_date, total)
#union#reporting1 visible + 1 hidden tests
query.sql · SQLite
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Report with a Grand Total Row · TechGradify