Revenue By Product
MediumSQLDatabaseSorting
Description
Write a SQL query to return each product with the total revenue (sum of amount) for that product. Order by product name ascending. **Output columns (in order):** product, revenue
Table:
orders| Column | Type |
|---|---|
| id | INT |
| product | TEXT |
| amount | INT |
Examples
Input:
CREATE TABLE orders (id INT, product TEXT, amount INT); INSERT INTO orders VALUES (1,'Apple',10),(2,'Banana',5),(3,'Apple',20);Output:
Apple|30
Banana|5Explanation:
Rows are grouped by product and their amounts are summed, giving each product its total revenue in alphabetical order.
Input:
CREATE TABLE orders (id INT, product TEXT, amount INT); INSERT INTO orders VALUES (1,'X',100),(2,'X',200);Output:
X|300Explanation:
Rows are grouped by product and their amounts are summed, giving each product its total revenue in alphabetical order.
Input:
CREATE TABLE orders (id INT, product TEXT, amount INT); INSERT INTO orders VALUES (1,'B',1),(2,'A',2),(3,'C',3);Output:
A|2
B|1
C|3Explanation:
Rows are grouped by product and their amounts are summed, giving each product its total revenue in alphabetical order.
Constraints
- •
Use standard SQL (SQLite).