Capstone: The Messy Data Analyst Challenge
0 of 6 checkpoints · 0 of 6 quiz questions
You've just been hired as a junior data analyst. Your manager hands you four raw public datasets and says: "I need a one-page briefing by the end of the day. Nobody has cleaned or checked this data. Tell me what you find, and tell me how sure you are."
The briefing has two parts. Part A: can we compare vehicle CO2 numbers across model years? Part B: which US states had the most seismic events in October 2026, compared with their populations? You'll work through six steps. Each one reuses a skill from the guides, ends with a graded SQL checkpoint, and shows the spreadsheet version so you can check your own work. Plan on about an hour. Your progress is saved only in this browser.
The tables are the same ones you've used all along: quakes (2,628 USGS seismic events from October 2026), vehicles (22,111 FuelEconomy.gov records, model years 2010 to 2027), state_population (66 Census rows) and state_abbrev (52 state-level areas: the 50 states, DC and Puerto Rico, with two-letter codes and names). Column letters in the downloadable CSVs match the spreadsheet formulas below: in quakes, J is place and K is type; in vehicles, B is year, C is make, K is atv_type and O is co2; in state_population, E is name and J is pop2024; in state_abbrev, A is the code and B the name.
How the spreadsheet formulas were checked. Every formula below was evaluated against the CSV data in LibreOffice Calc 26.8 and matched the SQL. They use standard Excel functions (COUNTIF, COUNTIFS, COUNTBLANK, AVERAGEIFS, EXACT, XLOOKUP, FILTER, SORT). XLOOKUP, FILTER and SORT need Excel 2021, 2024 or Microsoft 365. Where Google Sheets differs, the note says so. Those Google Sheets formulas follow Google's documented syntax; they were not tested in Sheets itself.
Step 1: Audit before you trust (Guides 1 and 2)
Before any analysis, find out what's missing and what looks missing. Remember the three kinds: real NULLs, blanks stored as empty strings, and placeholder numbers like -1. Here is a first look at the three tables:
SELECT COUNT(*) - COUNT(horizontal_error) AS missing_horizontal_error,
COUNT(*) - COUNT(mag_error) AS missing_mag_error,
SUM(place IS NULL) AS missing_place
FROM quakes;Output (real run against the practice database):
| missing_horizontal_error | missing_mag_error | missing_place |
|---|---|---|
| 17 | 5 | 1 |
SELECT COALESCE(NULLIF(atv_type, ''), 'Conventional') AS tech,
COUNT(*) AS n,
SUM(cylinders IS NULL) AS null_cylinders
FROM vehicles
GROUP BY tech
HAVING null_cylinders > 0
ORDER BY n DESC;Output (real run against the practice database):
| tech | n | null_cylinders |
|---|---|---|
| EV | 1670 | 1670 |
| FCV | 43 | 43 |
| eFCV | 2 | 2 |
The NULL cylinders aren't errors. Electric and fuel-cell vehicles have no cylinders, so those NULLs mean "not applicable." The blank atv_type values aren't NULLs either: atv_type IS NULL finds nothing, while atv_type = '' finds every conventional gasoline vehicle. And the population file isn't all states:
SELECT SUM(sumlev <> '040') AS not_states, COUNT(*) AS total_rows
FROM state_population;Output (real run against the practice database):
| not_states | total_rows |
|---|---|
| 14 | 66 |
In a spreadsheet: =COUNTBLANK(quakes!J2:J2629) counts blank cells (both truly empty cells and empty strings), =COUNTIF(quakes!K2:K2629, "<>earthquake") counts rows whose type is anything else, and =COUNTIF(vehicles!O2:O22112, -1) counts the -1 placeholders. Use bounded ranges for "<>" criteria: on a whole column, COUNTIF also counts the empty cells below your data.
Checkpoint 1: The audit row Not passed yet
Return one row with six numbers, in this order: the number of rows in quakes, the number of quakes rows whose type is not earthquake, the number of quakes rows with a NULL place, the number of rows in vehicles, the number of vehicles rows where co2 is the -1 placeholder, and the number of vehicles rows where atv_type is an empty string. Check your result: 2628, 2, 1, 22111, 3335, 16565.
Each number is a COUNT(*) from one table with its own WHERE. Put each in a scalar subquery like (SELECT COUNT(*) FROM quakes WHERE ...) and list them in one SELECT. The blank atv_type is an empty string, so use = '', not IS NULL.
Solution
SELECT (SELECT COUNT(*) FROM quakes) AS quake_rows,
(SELECT COUNT(*) FROM quakes WHERE type <> 'earthquake') AS not_earthquakes,
(SELECT COUNT(*) FROM quakes WHERE place IS NULL) AS missing_place,
(SELECT COUNT(*) FROM vehicles) AS vehicle_rows,
(SELECT COUNT(*) FROM vehicles WHERE co2 = -1) AS co2_placeholders,
(SELECT COUNT(*) FROM vehicles WHERE atv_type = '') AS blank_atv_type;Expected output:
Step 2: Standardize labels (Guide 3)
The same thing written two ways splits into two groups. You met CA and California in Guide 3. The vehicle data has the same problem with letter case: 501 rows say MINI and one says Mini.
SELECT make, COUNT(*) AS n
FROM vehicles
WHERE UPPER(make) = 'MINI'
GROUP BY make;Output (real run against the practice database):
| make | n |
|---|---|
| MINI | 501 |
| Mini | 1 |
Models do it too. The same Mercedes model appears as E350 4matic (20 rows) and E350 4Matic (1 row). Group by the raw column and you get two groups for one thing. UPPER(TRIM(...)) is a simple standardization: it makes the comparison ignore letter case and stray spaces, and it leaves your original data untouched.
Be careful with LIKE: in SQLite it already ignores letter case for plain English letters, so make LIKE 'mini' would have matched both spellings anyway. In SQLite, = and COUNT(DISTINCT ...) compare text case-sensitively by default, which is why the raw distinct count is higher. Other databases can follow different rules, so check yours.
In a spreadsheet: =COUNTIF(vehicles!C2:C22112, "MINI") returns 502, because COUNTIF ignores letter case, while the SQL WHERE make = 'MINI' returns 501. To get 501 in a spreadsheet, use =SUMPRODUCT(--EXACT(vehicles!C2:C22112, "MINI")). So the two tools can disagree on the same question, and neither is wrong. They have different rules for case. UNIQUE ignored letter case in LibreOffice, which returned 75 makes and 3,751 models, the same numbers as the cleaned SQL counts. To make the answer independent of any tool's case rule, normalize first: =COUNTA(UNIQUE(UPPER(vehicles!C2:C22112))) returned 75 in LibreOffice. In Google Sheets, how UNIQUE treats letter case was not tested here, so use the same normalizing idea there, =COUNTA(UNIQUE(ARRAYFORMULA(UPPER(vehicles!C2:C22112)))) (documented syntax; not tested in Sheets). California: =COUNTIF(quakes!J2:J2629, "*, CA") + COUNTIF(quakes!J2:J2629, "*, California").
Checkpoint 2: Raw versus standardized counts Not passed yet
Return one row with five numbers: the number of distinct make values as written, the number of distinct makes after UPPER(TRIM(make)), the number of distinct model values as written, the number after UPPER(TRIM(model)), and the number of quakes events whose place ends in either , CA or , California. Check your result: 76, 75, 3784, 3751, 59.
COUNT(DISTINCT make) counts spellings as written; COUNT(DISTINCT UPPER(TRIM(make))) counts them after standardizing. Do the same for model. For California, one WHERE with OR counts both endings in a single pass, so nothing is counted twice.
Solution
SELECT (SELECT COUNT(DISTINCT make) FROM vehicles) AS makes_raw,
(SELECT COUNT(DISTINCT UPPER(TRIM(make))) FROM vehicles) AS makes_clean,
(SELECT COUNT(DISTINCT model) FROM vehicles) AS models_raw,
(SELECT COUNT(DISTINCT UPPER(TRIM(model))) FROM vehicles) AS models_clean,
(SELECT COUNT(*) FROM quakes WHERE place LIKE '%, CA' OR place LIKE '%, California') AS california_events;Expected output:
Step 3: Transform: Part A, can we compare CO2 across years? (Guides 2 and 4)
Part A of the briefing is a table of average tailpipe CO2 by model year, with a flag for whether you'd trust it. First, the trap. A plain AVG(co2) treats the -1 placeholder as a real number:
SELECT year,
COUNT(*) AS records,
SUM(co2 = -1) AS placeholders,
ROUND(AVG(co2), 1) AS naive_avg_co2
FROM vehicles
WHERE year BETWEEN 2010 AND 2014
GROUP BY year
ORDER BY year;Output (real run against the practice database):
| year | records | placeholders | naive_avg_co2 |
|---|---|---|---|
| 2010 | 1106 | 1097 | 1.9 |
| 2011 | 1126 | 1112 | 1.9 |
| 2012 | 1146 | 1126 | 2.1 |
| 2013 | 1180 | 0 | 420.7 |
| 2014 | 1222 | 0 | 414 |
That table says CO2 jumped from about 2 to 420 g/mile between 2012 and 2013. It didn't. Almost every 2010 to 2012 row is a -1, and the plain average is mostly placeholders. Using NULLIF(co2, -1) the real average for 2012 is 178.9 g/mile, but it's based on just 20 of 1,146 rows, while 2013's 420.7 is based on all 1,180. The honest result isn't a trend at all. It's a warning about coverage. That's what the reliability column is for: a CASE that labels any year with under 50% real values as Low coverage and every other year Meets coverage threshold. The 50% line is an arbitrary exercise threshold, not a statistical standard: even 100% coverage doesn't prove the values are accurate or that the file covers every vehicle sold. A real NULL is also not a real value, which is why COUNT(NULLIF(co2, -1)) is the safest way to count them: it skips both the placeholder and any NULL.
In a spreadsheet: per year in A2, =COUNTIFS(vehicles!B2:B22112, A2, vehicles!O2:O22112, "<>-1") counts real values, =AVERAGEIFS(vehicles!O2:O22112, vehicles!B2:B22112, A2, vehicles!O2:O22112, "<>-1") is the average, and =IF(D2<50, "Low coverage", "Meets coverage threshold") is the CASE, where D2 holds the coverage percent on a 0 to 100 scale (like the 1.2 in the SQL output). If your cell holds a decimal formatted as a percentage, compare with 50% instead, or every year will look like low coverage. Without the "<>-1" criterion, AVERAGEIFS gives the same misleading 1.9 for 2011.
Checkpoint 3: CO2 by model year, with a reliability flag Not passed yet
For model years 2010 to 2014, return one row per year with: year, the number of records, the number of records with a real co2 value (not -1 and not NULL), the coverage percent rounded to 1 decimal place, the average co2 ignoring placeholders rounded to 1 decimal place, and a label that is Low coverage when coverage is below 50 percent and Meets coverage threshold otherwise (50 percent is an arbitrary exercise threshold). Sort by year. Check your result: 2010, 1106, 9, 0.8, 359.4, Low coverage is the first row, and 2013 and 2014 are Meets coverage threshold.
NULLIF(co2, -1) turns the placeholder into NULL. COUNT(NULLIF(...)) then counts real values and AVG(NULLIF(...)) skips the placeholders. COUNT(NULLIF(...)) skips both the placeholder and any NULL. Use 100.0 * so the division isn't whole-number division. Put the CASE on the same coverage expression, and GROUP BY year.
Solution
SELECT year,
COUNT(*) AS records,
COUNT(NULLIF(co2, -1)) AS with_co2,
ROUND(100.0 * COUNT(NULLIF(co2, -1)) / COUNT(*), 1) AS coverage_pct,
ROUND(AVG(NULLIF(co2, -1)), 1) AS avg_co2,
CASE WHEN 100.0 * COUNT(NULLIF(co2, -1)) / COUNT(*) < 50 THEN 'Low coverage' ELSE 'Meets coverage threshold' END AS coverage_flag
FROM vehicles
WHERE year BETWEEN 2010 AND 2014
GROUP BY year
ORDER BY year;Expected output:
Step 4: Join tables with mismatched keys: Part B (Guide 5)
Part B needs population next to event counts. The keys don't match: quakes.place is free text (52 km W of Petrolia, CA), state_abbrev has codes and names, and state_population mixes the nation, regions, divisions and states. Guide 5 built this join; here it is, with the two checks you should never skip. First, did any event match two lookup rows?
SELECT (SELECT COUNT(*)
FROM quakes q
JOIN state_abbrev s
ON q.place LIKE '%, ' || s.abbrev OR q.place LIKE '%, ' || s.name) AS joined_rows,
(SELECT COUNT(*)
FROM quakes q
WHERE EXISTS (SELECT 1 FROM state_abbrev s
WHERE q.place LIKE '%, ' || s.abbrev OR q.place LIKE '%, ' || s.name)) AS distinct_events;Output (real run against the practice database):
| joined_rows | distinct_events |
|---|---|
| 902 | 902 |
Both are 902, so the join did not multiply any source row: no event matched two lookup rows. That does not show the original data has no duplicate events, and it does not show that every match is the right state. For the second question you read the distinct endings, as Guide 5 did. Second, what didn't match? 1,726 of the 2,628 events (65.7%) found no state. Most are other countries, but three groups are US territories that the lookup doesn't cover:
SELECT TRIM(replace(place, rtrim(place, replace(place, ',', '')), '')) AS region,
COUNT(*) AS n
FROM quakes q
WHERE place LIKE '%,%'
AND NOT EXISTS (SELECT 1 FROM state_abbrev s
WHERE q.place LIKE '%, ' || s.abbrev OR q.place LIKE '%, ' || s.name)
AND (place LIKE '%U.S.%' OR place LIKE '%Guam' OR place LIKE '%Mariana Islands')
GROUP BY region
ORDER BY n DESC;Output (real run against the practice database):
| region | n |
|---|---|
| U.S. Virgin Islands | 32 |
| Guam | 14 |
| Northern Mariana Islands | 13 |
The lookup has the 50 states, DC and Puerto Rico (itself a territory), but not the other US territories, so those events drop out. For a "US states" briefing that's a reasonable scope, but it's a decision to write down, not an accident. When you join to state_population, filter to sumlev = '040' so you only match state-level rows, and keep the leading zero: it's the text '040', not the number 40.
In a spreadsheet: a lookup replaces the join. Put each state's code in A2 and name in B2 (copy them from the state_abbrev sheet), then =COUNTIF(quakes!J2:J2629, "*, " & A2) + COUNTIF(quakes!J2:J2629, "*, " & B2) counts events and =XLOOKUP(B2, state_population!E2:E67, state_population!J2:J67, "not found") fetches the 2024 population. The "not found" text plays the role of a LEFT JOIN you then check for NULLs. All 52 names were found, and the 52 rows summed to 902 events with 36 states at zero, the same as SQL.
Checkpoint 4: Events and population per matched state Not passed yet
Match each event to a state using the code or the full name at the end of place (like Guide 5), then join state_population on the name using only state-level rows (sumlev = '040'). Return one row per matched state with: the state name, the number of events, and its pop2024. Sort by events from most to fewest, then by name A to Z. Check your result: 16 rows, the events add up to 902, and the first row is Alaska, 653, 740133.
The first JOIN needs OR so it accepts both the code (, CA) and the full name (, Alaska). The second JOIN matches p.name = s.name and also p.sumlev = '040', with the leading zero in quotes. Add p.pop2024 to the GROUP BY (or wrap it in MAX) since you select it.
Solution
SELECT s.name,
COUNT(*) AS events,
p.pop2024
FROM quakes q
JOIN state_abbrev s
ON q.place LIKE '%, ' || s.abbrev
OR q.place LIKE '%, ' || s.name
JOIN state_population p
ON p.name = s.name AND p.sumlev = '040'
GROUP BY s.name, p.pop2024
ORDER BY events DESC, s.name;Expected output:
Step 5: Verify independently in a spreadsheet (Guide 6)
A result you can reproduce a second way is a result you can defend. Before you finalize, spot-check five numbers in a spreadsheet. If the two tools disagree, don't pick the one you like better. Find out why.
1. California events, two spellings: both give 59
- SQL:
WHERE place LIKE '%, CA' OR place LIKE '%, California' - Spreadsheet:
=COUNTIF(quakes!J2:J2629,"*, CA")+COUNTIF(quakes!J2:J2629,"*, California")
2. Alaska events: both give 653
- SQL:
WHERE place LIKE '%, Alaska' - Spreadsheet:
=COUNTIF(quakes!J2:J2629,"*, Alaska")
3. Alaska events per million residents: both give 882.27
- SQL: events × 1,000,000 ÷
pop2024forAlaska(state level) - Spreadsheet:
=ROUND(COUNTIF(quakes!J2:J2629,"*, Alaska")*1000000/XLOOKUP("Alaska",state_population!E2:E67,state_population!J2:J67),2)
4. Average CO2, model year 2012, without placeholders: both give 178.9
- SQL:
AVG(NULLIF(co2, -1))withWHERE year = 2012 - Spreadsheet:
=ROUND(AVERAGEIFS(vehicles!O2:O22112,vehicles!B2:B22112,2012,vehicles!O2:O22112,"<>-1"),1)
5. MINI records in any letter case: both give 502
- SQL:
WHERE UPPER(make) = 'MINI' - Spreadsheet:
=COUNTIF(vehicles!C2:C22112,"MINI")
Notice what a careless spreadsheet formula does here. =COUNTIF(quakes!J2:J2629, "*Alaska*") returns 656, not 653: the extra three are offshore labels like Gulf of Alaska that have no , Alaska ending. Neither rule is wrong, but the spreadsheet has to use the same rule as the SQL, or you can't reconcile them. In Google Sheets the same formulas work with the same syntax (COUNTIF wildcards, AVERAGEIFS and XLOOKUP are all documented there); I haven't run them in Sheets.
Checkpoint 5: The spot-check row Not passed yet
Return one row with the five numbers you'll check in the spreadsheet, in this order: California events (ending , CA or , California), Alaska events (ending , Alaska), Alaska events per million residents using pop2024 for Alaska at state level, rounded to 2 decimal places, the average co2 for model year 2012 ignoring -1 rounded to 1 decimal place, and the number of vehicles rows whose make is MINI in any letter case. Check your result: 59, 653, 882.27, 178.9, 502.
Five scalar subqueries in one SELECT. For the rate, divide Alaska's event count (times 1000000.0) by a second subquery that fetches pop2024 from state_population for Alaska with sumlev = '040'. For MINI, compare UPPER(make) with 'MINI'.
Solution
SELECT (SELECT COUNT(*) FROM quakes WHERE place LIKE '%, CA' OR place LIKE '%, California') AS california,
(SELECT COUNT(*) FROM quakes WHERE place LIKE '%, Alaska') AS alaska,
(SELECT ROUND(COUNT(*) * 1000000.0 / (SELECT pop2024 FROM state_population WHERE name = 'Alaska' AND sumlev = '040'), 2)
FROM quakes WHERE place LIKE '%, Alaska') AS alaska_per_million,
(SELECT ROUND(AVG(NULLIF(co2, -1)), 1) FROM vehicles WHERE year = 2012) AS avg_co2_2012,
(SELECT COUNT(*) FROM vehicles WHERE UPPER(make) = 'MINI') AS mini_records;Expected output:
Step 6: The final table and the briefing
Now put it together: one clean table for Part B. Keep only the states with at least 5 events (a rate built on 1 or 2 events is mostly noise), divide by the 2024 population, and label each state with a rate band. The bands are practice cut-offs, not scientific categories: High rate is 15 or more events per million residents, Medium rate is 5 up to 15, and Low rate is under 5. Decide the band from the unrounded rate and round only for display; otherwise a rate of 14.996 would display as 15.00 yet land in the wrong band. A CASE evaluates top to bottom, so check the highest band first. A common way to structure the query is a CTE that builds the per-state counts first, then a join to the population table.
In a spreadsheet, this is the helper table from Step 4 plus =ROUND(C2*1000000/D2, 2) for the rate and =IF(C2*1000000/D2>=15, "High rate", IF(C2*1000000/D2>=5, "Medium rate", "Low rate")) for the band (computed from the unrounded rate, like the SQL). With the helper table in A1:F53 (columns: code, name, events, population, rate, band), Excel 2021 or 365 can sort and filter in one step: =SORT(FILTER(B2:F53, C2:C53>=5), 4, -1). In Google Sheets, FILTER and SORT exist, but the descending flag is FALSE instead of -1: =SORT(FILTER(B2:F53, C2:C53>=5), 4, FALSE) (documented syntax; not tested in Sheets). The LibreOffice check of the Excel formula returned the same 11 rows, in the same order, as the SQL.
Final checkpoint: The state briefing table Not passed yet
Build the final table. Match events to states as before, keep only states with at least 5 events, and join state_population on sumlev = '040'. Return: the state name, events, the rate per million residents (events times 1,000,000 divided by pop2024) rounded to 2 decimal places, and a band, decided from the unrounded rate (round only for display): High rate for 15 or more per million, Medium rate for 5 up to 15, and Low rate for under 5. Sort by rate from highest to lowest, then by name. Check your result: 11 rows, the first is Alaska, 653, 882.27, High rate, and three states are High rate.
Build the per-state counts in a CTE (WITH per_state AS (...)) with HAVING COUNT(*) >= 5, then join that to state_population. Compute the rate with events * 1000000.0 / pop2024, and use that unrounded value in the CASE; round only the displayed column. In the CASE, test >= 15 first, then >= 5, then ELSE. Sort by the rate, then name.
Solution
WITH per_state AS (
SELECT s.name, COUNT(*) AS events
FROM quakes q
JOIN state_abbrev s
ON q.place LIKE '%, ' || s.abbrev
OR q.place LIKE '%, ' || s.name
GROUP BY s.name
HAVING COUNT(*) >= 5
)
SELECT ps.name,
ps.events,
ROUND(ps.events * 1000000.0 / p.pop2024, 2) AS events_per_million,
CASE WHEN ps.events * 1000000.0 / p.pop2024 >= 15 THEN 'High rate'
WHEN ps.events * 1000000.0 / p.pop2024 >= 5 THEN 'Medium rate'
ELSE 'Low rate' END AS rate_band
FROM per_state ps
JOIN state_population p
ON p.name = ps.name AND p.sumlev = '040'
ORDER BY events_per_million DESC, ps.name;Expected output:
Write the briefing
The last step has no query: explain what you found and how sure you are. Write your own briefing before you look at the model answer. You'll learn more from deciding what matters than from paraphrasing someone else's conclusions. Writing is optional and doesn't affect the completion card. Nothing is sent anywhere: your text is saved only in this browser.
Your analyst briefing
0 words written · Optional. Saved only in this browser.
Show the model briefing (try your own first)
Part A: vehicle CO2. The FuelEconomy.gov file has no usable CO2 value for 98% to 99% of model year 2010, 2011 and 2012 rows (stored as -1), so those years are flagged Low coverage and can't be compared with later ones. Model years 2013 and 2014 meet the coverage threshold (1,180 and 1,222 rows, averaging 420.7 and 414.0 g/mile), though full coverage still doesn't prove the values are accurate. A plain average would have shown a false jump from about 2 to 420.
Part B: state seismic activity. In the USGS M2.5+ events from October 1 to November 1, 2026, 902 of 2,628 (34.3%) matched a US state, DC or Puerto Rico. Alaska had 653 of them (72.4%), or 882.27 per million residents. Of the 11 states with at least 5 events, three are in the high band: Alaska, New Mexico (19.72) and Hawaii (17.98).
Assumptions and limits. Say these out loud, because they change how far you can trust the numbers:
- The events cover one month, and the population denominator is a 2024 estimate.
- A rate of recorded events per million residents is a way to compare groups of different sizes. It is not a measure of earthquake hazard or risk.
- Locations come from the text in
place. Offshore labels without a comma (likeGulf of Alaska) aren't matched, and the lookup excludes the other US territories (U.S. Virgin Islands, Guam, Northern Mariana Islands). - Two of the 2,628 rows are not earthquakes (an explosion and a landslide), and one has no
place. - The coverage threshold (50%) and the rate bands (15 and 5) are arbitrary practice cut-offs, and bands are decided on unrounded rates.
- The spreadsheet checks agreed with the SQL after the matching rules were made the same, which is evidence about the method, not about the data's accuracy.