Line Item Total

EasySQLDatabaseSorting

Description

Write a SQL query to return each line item id and its total, computed as price times quantity, ordered by id ascending. **Output columns (in order):** id, total

Table:lineitems
ColumnType
idINT
priceINT
quantityINT

Examples

Input:CREATE TABLE lineitems (id INT, price INT, quantity INT); INSERT INTO lineitems VALUES (1,10,2),(2,5,3),(3,7,0);
Output:1|20 2|15 3|0
Explanation:

Multiplying price by quantity for each row gives the per-line total returned by id.

Input:CREATE TABLE lineitems (id INT, price INT, quantity INT); INSERT INTO lineitems VALUES (1,100,1);
Output:1|100
Explanation:

Multiplying price by quantity for each row gives the per-line total returned by id.

Input:CREATE TABLE lineitems (id INT, price INT, quantity INT); INSERT INTO lineitems VALUES (2,4,4),(1,3,3);
Output:1|9 2|16
Explanation:

Multiplying price by quantity for each row gives the per-line total returned by id.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.