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
ColumnType
idINT
productTEXT
amountINT

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|5
Explanation:

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|99
Explanation:

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|1
Explanation:

Each product gets a row counting its orders and summing their amounts, in alphabetical order.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.