A through L
- O(log n) · Easy
- Free
- SQL
- comparisons
- conditionals
- sorting
Problem
On enrollment day the school runs two lines to keep things moving. Line 1 is for anyone whose name starts with a letter from A through L, and line 2 is for M through Z. Lucas asks which one is his: line 1, because his name starts with L.
Show each student's name and their line number, in that order, sorted alphabetically.
Here, < and > between two pieces of text ask which one comes first in the dictionary, which is why they worked with dates:
'Henry' < 'Julia' is true. One catch: any uppercase letter comes before any lowercase one.
What it has to return
These rows, in this order
| name | line |
|---|---|
| Emma | 1 |
| Henry | 1 |
| Julia | 1 |
| Leo | 1 |
| Lucas | 1 |
| Megan | 2 |
| Sara | 2 |
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
FROM students
WHERE name <= 'L'
ORDER BY name;It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.