AnalystPath

Menu Item Totals Across Tickets

SQLEasyJunior level~15 min

Problem

Table: `dish`

| Column Name | Type |
|---|---|
| dish_id | int |
| dish_name | varchar |

`dish_id` is the primary key.

Table: `ticket`

| Column Name | Type |
|---|---|
| ticket_id | int |
| dish_id | int |
| pending | int |
| served | int |
| comped | int |
| voided | int |

`ticket_id` is the primary key. Each ticket records, for one dish, the amount that is still pending, served, comped, and voided.

For every dish, report the total `pending`, `served`, `comped`, and `voided` amounts summed over all of its tickets. A dish with no tickets must still appear with totals of 0. Return the columns `dish_name`, `pending`, `served`, `comped`, `voided`, ordered by `dish_name`.

Tables

Example rows — the live problem includes the full dataset.

dish
dish_iddish_name
1Falafel
2Hummus
3Shakshuka
ticket
ticket_iddish_idpendingservedcompedvoided
88110501
8912310
9024422

Expected output

Your answer should return 3 rows with the columns dish_name, pending, served, comped, voided.

Starter code (SQL)

SELECT *
FROM dish;

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