SQL QuestSQL Interview Questions › Conditional Logic

Age Group Survival Analysis

MediumFreeQuerying BasicsConditional LogicAggregation & Grouping

Group Titanic passengers into age bands: 'Child' (age < 13), 'Teen' (13–17), 'Adult' (18–59), 'Senior' (60+), 'Unknown' (NULL age). For each group show: age_group, passengers, survival_rate (%, 1 dec). Sort by survival_rate descending.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

passengers

passenger_idsurvivedpclassnamesexagesibspparchfareembarked
103Braund, Mr. Owen Harrismale22107.25S
211Cumings, Mrs. John Bradleyfemale381071.28C
313Heikkinen, Miss. Lainafemale26007.93S

Expected output: 5 age groups with survival rates

Hint

Check IS NULL FIRST in your CASE expression — CASE WHEN age IS NULL THEN 'Unknown' WHEN age < 13 THEN 'Child' ... to avoid NULL comparison issues

Concepts

SELECT CASE GROUP BY Aggregation CASE + GROUP BY

Practise the topic: SQL practice questions · CASE WHEN practice · GROUP BY exercises

In these company practice sets

Snowflake

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Movie Rating Tier BreakdownMedium · FreeGenre Financial ReportMedium · FreeDepartment Compensation ReportMedium · FreePivot: Order Status by CountryMedium · FreeGenre Box Office ReportMedium · FreeFare Imputation AnalysisMedium · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test