반응형
You have access to a table of monsters as follows:
monsters schema
- id
- name
- legs
- arms
- characteristics
In each row, the characteristic column has a single comma. Your job is to find it using position(). You must return a table with the format as follows:
output schema
- id
- name
- comma
The comma column will contain the position of the comma within the characteristics string. Order the results by comma.
Solution:
SELECT
id,
name,
POSITION(',' in characteristics) AS comma
FROM
monsters
ORDER BY
comma;
POSITION is a function that returns an index after checking whether a string is included in the corresponding column.
Result:
id | name | comma |
9 | Random | 1 |
7 | Random | 3 |
5 | Martin | 4 |
1 | Cyril | 4 |
6 | Random | 4 |
2 | Tiny | 6 |
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
BASICS: Length based SELECT with LIKE (0) | 2022.06.08 |
---|---|
SQL Basics: Repeat and Reverse (0) | 2022.06.07 |
Register for the Party (SQL for Beginners #3) (0) | 2022.06.05 |
SQL Grasshopper: Select Columns (0) | 2022.06.05 |
Remove String Spaces (0) | 2022.06.04 |