AnalystPath

Total Spend per Diner

SQLEasyJunior level~15 min

Problem

A restaurant tracks every order line and the menu price of each dish. Table `orders` has `(order_id, dish_id, diner_id, servings)`, and table `menu` has `(dish_id, unit_price)`.

Report the total amount each diner spent, where a single order line contributes servings multiplied by unit_price. Order the result by total spend descending, and by `diner_id` ascending when two diners spent the same.

Return the columns `diner_id` and `total_spend`.

Tables

Example rows — the live problem includes the full dataset.

orders
order_iddish_iddiner_idservings
1110110
221011
331023
menu
dish_idunit_price
110
225
315

Expected output

Your answer should return 3 rows with the columns diner_id, total_spend.

Starter code (SQL)

SELECT *
FROM orders;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions