SQL QuestSQL Interview Questions › Conditional Logic

Family Size Survival Buckets

MediumFreeQuerying BasicsConditional LogicAggregation & Grouping

A sociology paper is measuring how family size affected survival. Compute family_size = sibsp + parch + 1 (siblings + parents/children + the passenger themselves). Bucket into 'Solo' (exactly 1), 'Small family' (2–4), 'Large family' (5 or more). For each bucket, show family_category, passenger_count, survival_rate (as a percent, rounded to 1 decimal), and avg_fare (rounded to 2 decimals). Sort by survival_rate descending. This pattern — compute → categorize → aggregate — is bread-and-butter analytics.

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: Solo | 537 | 30.3 | 21.24

Hint

Use CASE in both SELECT and GROUP BY the SAME expression (or alias it). survival_rate = 100.0 * SUM(survived) / COUNT(*). Keep the 100.0 as a float so integer division doesn't zero out the result.

Concepts

SELECT CASE GROUP BY Aggregation Calculated Column BETWEEN CASE + GROUP BY

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

In these company practice sets

Plaid · 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