Skip to the content

Youngest first

Problem

End-of-year photo, with the whole school on the bleachers. The photographer wants a list for calling them up: first year first, then second year, and third year last. And within each year, from the youngest to the oldest. students has no ages: what it has is the date each student was born.

Show the name, the year, and the date of birth, in that order. If two students in the same year were born on the same day, they go alphabetically.

What it has to return

These rows, in this order

nameyearborn
Emma12012-11-02
Lucas12012-03-14
Henry22011-06-21
Julia22011-01-30
Sara32010-12-25
Megan32010-09-09
Leo32010-04-17

This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.

You start with this

SQL

SELECT name, year, born
FROM students
ORDER BY year;
Solve this challenge

It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.

More O(log n) challenges

See all challenges →