Population by Census region
IntermediateCASE mapping codesState population estimates (U.S. Census Bureau, Vintage 2024)
The region column holds codes: 1 = Northeast, 2 = Midwest, 3 = South, 4 = West (Puerto Rico's code is X). For state-level rows, return the region name and total pop2024, largest first. Label anything else Other.
Solution
SELECT CASE region
WHEN '1' THEN 'Northeast'
WHEN '2' THEN 'Midwest'
WHEN '3' THEN 'South'
WHEN '4' THEN 'West'
ELSE 'Other'
END AS region_name,
SUM(pop2024) AS total
FROM state_population
WHERE sumlev = '040'
GROUP BY region_name
ORDER BY total DESC;Expected output:
Hint
region is text, so compare with '1', '2' and so on.
Same question in Excel / Google Sheets
Helper column =SWITCH(B2,"1","Northeast","2","Midwest","3","South","4","West","Other"), then SUMIFS or a 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.