Collapse drive labels into groups
IntermediateCASE + LIKEVehicle fuel economy (FuelEconomy.gov, model years 2010–2027)
Group drive into AWD/4WD (anything mentioning All-Wheel or 4-Wheel), FWD, RWD, and Other. Return group and count, largest first.
Solution
SELECT CASE
WHEN drive LIKE '%4-Wheel%' OR drive LIKE '%All-Wheel%' THEN 'AWD/4WD'
WHEN drive LIKE 'Front%' THEN 'FWD'
WHEN drive LIKE 'Rear%' THEN 'RWD'
ELSE 'Other'
END AS drive_group,
COUNT(*) AS n
FROM vehicles
GROUP BY drive_group
ORDER BY n DESC;Expected output:
Hint
Check the 4-Wheel / All-Wheel patterns first with LIKE '%4-Wheel%' and LIKE '%All-Wheel%'.
Same question in Excel / Google Sheets
=IF(OR(ISNUMBER(SEARCH("4-Wheel",F2)),ISNUMBER(SEARCH("All-Wheel",F2))),"AWD/4WD",IF(LEFT(F2,5)="Front","FWD",IF(LEFT(F2,4)="Rear","RWD","Other")))
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.