Blended cost per litre
Petronas buys fuel from different suppliers in batches of different sizes and different prices, then sells it as one undifferentiated product at the pump. Finance wants the true blended cost per litre for each fuel grade — not a simple average of the batch prices, which ignores that a 50,000-litre batch and a 500-litre batch shouldn't count equally.
From fuel_batches, return each grade, and blended_cost_per_litre — the volume-weighted average cost per litre (total cost across all batches of that grade, divided by total litres of that grade), rounded to 4 decimal places. Order the output by grade.
Schema
| batch_id | INT |
| grade | TEXT |
| litres | NUMERIC(12,2) |
| cost_per_litre | NUMERIC(10,4) |
Basic
The example input, expected output, and walkthrough for this question unlock with a Basic plan.
Basic
The reference solution and walkthrough for this question unlock with a Basic plan.
Basic
This is a Basic question
Premium practice questions unlock with a Basic plan. The full solution, expected output, and grading are available to Basic members.
RM 25/mo · cancel anytime