forked from yunuserbas/SqlQueries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22_SplitPart.sql
More file actions
39 lines (23 loc) · 713 Bytes
/
22_SplitPart.sql
File metadata and controls
39 lines (23 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- QUESTION
-- You have access to a table of monsters as follows:
-- monsters schema
-- id
-- name
-- legs
-- arms
-- characteristics
-- The monsters in the provided table have too many characteristics, they really only need one each.
-- Your job is to trim the characteristics down so that each monster only has one. If there is only one already, provide that.
-- If there are multiple, provide only the first one (don't leave any commas in there).
-- You must return a table with the format as follows:
-- output schema
-- id
-- name
-- characteristic
-- Order by id
-- SOLUTION
SELECT id,
name,
split_part(characteristics, ',', 1) as characteristic
FROM monsters
ORDER BY id;