Give blanks a real label
IntermediateNULLIF, COALESCEVehicle fuel economy (FuelEconomy.gov, model years 2010–2027)
Count records per technology type, showing blank atv_type as Conventional. Return label and count, largest first.
Solution
SELECT COALESCE(NULLIF(atv_type, ''), 'Conventional') AS tech, COUNT(*) AS n
FROM vehicles
GROUP BY tech
ORDER BY n DESC;Expected output:
Hint
COALESCE(NULLIF(atv_type, ''), 'Conventional') turns '' into NULL, then NULL into a label.
Same question in Excel / Google Sheets
Helper column =IF(K2="","Conventional",K2), then pivot.
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.