Units Dispensed per Drink
Problem
Table: `dispense_log`
| Column Name | Type |
|---|---|
| log_id | int |
| drink_id | int |
| machine_id | int |
| units | int |
`log_id` is the primary key. Each row records how many `units` of a drink were dispensed in one transaction.
Report the total number of units dispensed for every `drink_id` under the alias `total_units`. Return the result in any order.
Tables
Example rows — the live problem includes the full dataset.
dispense_log
| log_id | drink_id | machine_id | units |
|---|---|---|---|
| 1 | 100 | 9 | 10 |
| 2 | 100 | 4 | 12 |
| 7 | 200 | 4 | 15 |
Expected output
Your answer should return 2 rows with the columns drink_id, total_units.
Starter code (SQL)
SELECT *
FROM dispense_log;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