Given the table below:
** names table schema **
- id
- prefix
- first
- last
- suffix
Your task is to use a select statement to return a single column table containing the full title of the person (concatenate all columns together except id), as follows:
** output table schema **
- title
Don't forget to add spaces.
Solution:
SELECT
CONCAT(prefix,' ',first,' ',last,' ',suffix) AS title
FROM
names
You can use the 'CONCAT_WS' function to avoid repeating whitespace delimiters.
SELECT
CONCAT_WS(' ', prefix, first, last, suffix) AS title
FROM
names
Result:
| title |
| Mrs. Dante Kuhic I |
| Dr. Blanche Corwin Sr. |
| Miss Clinton Goldner DDS |
| Ms. Jermaine Walker II |
| Mrs. Abbie Spinka Jr. |
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
| SQL with Sailor Moon: Thinking about JOINs... (0) | 2022.07.06 |
|---|---|
| SQL with Pokemon: Damage Multipliers (0) | 2022.07.05 |
| SQL easy regex extraction (0) | 2022.07.03 |
| SQL: Regex String to Table (0) | 2022.07.03 |
| SQL with Harry Potter: Sorting Hat Comparators (0) | 2022.07.01 |