Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
A delivery label has room for an initial and a surname, not a full name. The design says Ada Okafor should print as A. Okafor.
Return customer_id and a display_name built from full_name: the first letter in upper case, a full stop, a space, then everything after the first space. Order by customer_id.
Result columns · in this order
customer_id | The customer. |
display_name | Upper-case initial, a full stop and a space, then everything after the first space in the name. |
How to approach it
INSTR finds the first space; SUBSTR from one past it to the end is the surname.
Sample input
| customer_id | full_name | region | signed_up_on |
|---|---|---|---|
| c1 | Ada Okafor | North | 2025-11-02 |
| c2 | Bo Lindqvist | null | 2025-12-14 |
| c3 | Chen Wei | South | 2026-01-03 |
| c4 | Dara O'Neill | North | 2026-01-20 |
| c5 | Eve Marsh | null | 2026-02-01 |
5 rows — all rows shown.
Expected output
| customer_id | display_name |
|---|---|
| c1 | A. Okafor |
| c2 | B. Lindqvist |
| c3 | C. Wei |
| c4 | D. O'Neill |
| c5 | E. Marsh |
5 rows — all rows shown.
Constraints
full_name — do not hard-code any name.SUBSTR(name, 1, 1) is the first character.Dara O'Neill. An apostrophe inside stored data is just data — it only needs doubling when you type a literal containing one.customer_id.Worked example
Ada Okafor has its first space at position 4. SUBSTR(full_name, 1, 1) gives A, and SUBSTR(full_name, 4 + 1) — substring from position 5 to the end — gives Okafor. Concatenated with '. ' between them, that is A. Okafor.
The + 1 is the part people miss. SUBSTR(full_name, INSTR(full_name, ' ')) starts at the space and yields Okafor with a leading blank, which then prints as A. Okafor with a double space.
Dara O'Neill comes out as D. O'Neill. Nothing special is required for the apostrophe: it is a character in the column, not punctuation in your query.
What this tests
Substring and position functions, 1-based string indexing, and whether an apostrophe in the data makes you reach for an escape it does not need.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.