SQL Quest › SQL Interview Questions › Aggregation & Grouping
Counting Rows
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". Free accounts get 10 free challenge solves, and this can be one of them.
Schema
passengers
| passenger_id | survived | pclass | name | sex | age | sibsp | parch | fare | embarked |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22 | 1 | 0 | 7.25 | S |
| 2 | 1 | 1 | Cumings, Mrs. John Bradley | female | 38 | 1 | 0 | 71.28 | C |
| 3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26 | 0 | 0 | 7.93 | S |
Expected output: One row: total count, survivor count, non-null age count
Hint
Concepts
SELECT COUNT Aggregation
Practise the topic: SQL practice questions · GROUP BY exercises
Read the concept: How to find duplicates in SQL
Related questions
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