SQL QuestSQL Interview Questions › Aggregation & Grouping

Counting Rows

EasyFreeQuerying BasicsAggregation & Grouping

Answer three questions about the passengers table in a single query: How many total passengers are there? How many survived? How many have a known age (age is not NULL)? Name the columns total, survived, and known_age.

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: One row: total count, survivor count, non-null age count

Hint

COUNT(*) counts all rows. SUM(survived) counts survivors (since survived is 0 or 1). COUNT(age) counts only non-NULL ages.

Concepts

SELECT COUNT Aggregation

Practise the topic: SQL practice questions · GROUP BY exercises

Related questions

SUM, AVG, MIN, MAXEasy · FreeGROUP BY BasicsEasy · FreeMonthly Order CountEasy · FreeHow Many Genres Do We Cover? (DISTINCT)Easy · FreeFemale Survivor CountEasy · FreeAverage Salary by DepartmentEasy · 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