Best combined MPG per year (EVs excluded)
Advancedwindow functionsVehicle fuel economy (FuelEconomy.gov, model years 2010–2027)
For each model year, return year, make, model and comb_mpg of the highest-comb_mpg record that is not an EV (atv_type <> 'EV'). Break ties by make then model A→Z. Order by year.
Solution
WITH ranked AS (
SELECT year, make, model, comb_mpg,
ROW_NUMBER() OVER (PARTITION BY year ORDER BY comb_mpg DESC, make, model) AS rn
FROM vehicles
WHERE atv_type <> 'EV'
)
SELECT year, make, model, comb_mpg FROM ranked WHERE rn = 1 ORDER BY year;Expected output:
Hint
ROW_NUMBER() OVER (PARTITION BY year ORDER BY comb_mpg DESC, make, model), then keep row 1.
Same question in Excel / Google Sheets
Sort by year A→Z, comb_mpg Z→A, make, model; then Remove Duplicates on year (keeps the first row per year).
Download the CSV from the datasets page. Column letters assume the CSV opens with its header in row 1.
Tip: Ctrl+Enter (⌘+Enter on Mac) checks your answer. Everything runs in your browser; nothing you type is sent anywhere.