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

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

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

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

Rows are grouped by product and their amounts are summed, giving each product its total revenue in alphabetical order.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.