Orders and Revenue Per Product
MediumSQLDatabaseSorting
Description
Write a SQL query to return each product with its order count and total amount, ordered by product ascending. **Output columns (in order):** product, cnt, total
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,'A',10),(2,'A',20),(3,'B',5);Output:
A|2|30
B|1|5Explanation:
Each product gets a row counting its orders and summing their amounts, in alphabetical order.
Input:
CREATE TABLE orders (id INT, product TEXT, amount INT); INSERT INTO orders VALUES (1,'Solo',99);Output:
Solo|1|99Explanation:
Each product gets a row counting its orders and summing their amounts, in alphabetical order.
Input:
CREATE TABLE orders (id INT, product TEXT, amount INT); INSERT INTO orders VALUES (1,'B',1),(2,'A',1);Output:
A|1|1
B|1|1Explanation:
Each product gets a row counting its orders and summing their amounts, in alphabetical order.
Constraints
- •
Use standard SQL (SQLite).