SQL QuestSQL Interview Questions › Aggregation & Grouping

Class Survival Breakdown

MediumFreeQuerying BasicsAggregation & Grouping

The maritime inquiry board needs a summary by passenger class. The passengers table gives you pclass and survived; the other four columns you build yourself with AS.

Produce exactly these 5 output columns, in this order: pclass, total (passenger count), survivors, deaths, survival_rate (percentage, rounded to exactly 1 decimal). Order by pclass.

The checker compares result values in column order — an extra column, a missing column, or an unrounded rate won't pass even if your logic is right.

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: 3 rows — one per class with full survival stats

Hint

SUM(survived) counts survivors since survived=1. Deaths = COUNT(*) - SUM(survived). Survival rate = 100.0 * SUM(survived) / COUNT(*)

Concepts

SELECT GROUP BY Aggregation

Practise the topic: SQL practice questions · 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

Department Roster with GROUP_CONCATMedium · FreeMovie Rating Tier BreakdownMedium · FreeFull Survival Dashboard by ClassMedium · FreeGenre Financial ReportMedium · FreeDepartment Compensation ReportMedium · FreeConsistent Director 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