Practice · Art & Cinema · Medium
For the cultural figures who have died (death_year is not NULL), return their average lifespan in years as avg_lifespan, rounded to 1 decimal.
Runs in your browser. No signup needed.
Use cultural_figures. Lifespan = death_year − birth_year; only include rows where death_year IS NOT NULL.
SELECT ROUND(AVG(death_year - birth_year), 1) AS avg_lifespan
FROM cultural_figures
WHERE death_year IS NOT NULL;
The reference solution is checked automatically when you run your query on the practice page — results are compared row by row.
If you forget the IS NOT NULL filter, SQL skips the NULLs inside AVG automatically — but death_year − birth_year would still be NULL for the living, so filtering makes your intent explicit. (SQLite docs)