Which rows are actually states?
Beginnertext codesState population estimates (U.S. Census Bureau, Vintage 2024)
The Census file mixes the nation, regions, divisions and states. State-level rows have sumlev = '040' (text, with a leading zero). How many such rows are there?
Solution
SELECT COUNT(*) FROM state_population WHERE sumlev = '040';Expected output:
Hint
Try sumlev = 40 and sumlev = '040'. Which one works, and why?
Same question in Excel / Google Sheets
Watch out: Excel may turn 040 into 40 on import. Import the column as Text, then =SUMPRODUCT(--(A2:A67="040")).
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.