Total Revenue by Region
Easysql
Learn the Concept: GROUP BYWrite a query returning region and total (sum of amount) for each region, ordered by region.
sqlCREATE TABLE orders ( id INTEGER PRIMARY KEY, region TEXT NOT NULL, product TEXT NOT NULL, amount INTEGER NOT NULL );
Sample data:
sqlINSERT INTO orders (id, region, product, amount) VALUES (1, 'North', 'Widget', 200), (2, 'North', 'Gadget', 150), (3, 'South', 'Widget', 100), (4, 'South', 'Gadget', 50), (5, 'North', 'Widget', 300), (6, 'East', 'Widget', 400);
Example 1
Input
(none)
Output
region total East 400 North 650 South 150
GROUP BY collapses rows into one per region, and SUM aggregates within each group. Reference: SELECT region, SUM(amount) AS total FROM orders GROUP BY region ORDER BY region;
Related Problems
- Create a disposable database with explicit text defaultsEasy · sqlSolve Problem
- Select one student occurrence by identityEasy · sqlSolve Problem
- List immediate lab childrenEasy · sqlSolve Problem