Challenge: Two Singers
Uppgift
Swipe to start coding
Find the names of the oldest and youngest singers (i. e. singers with oldest and newest releases). Return two records containing the singer's name (naming
), his song (title
), and release date (year
).
Note that some fields can be NULL, excpet year
. Thus, you should add WHERE statement to include all albums where the year is not null. Other fields can be NULL.
Print two records in total: first one is for the oldest singer, and the second one is for the youngest singer.
Lösning
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(SELECT singers.naming, songs.title, albums.year
FROM songs
FULL OUTER JOIN singers
ON singers.id = songs.singer_id
FULL OUTER JOIN albums
ON albums.id = songs.album_id
WHERE year IS NOT null
ORDER BY year
LIMIT 1)
UNION ALL
(SELECT singers.naming, songs.title, albums.year
FROM songs
FULL OUTER JOIN singers
ON singers.id = songs.singer_id
FULL OUTER JOIN albums
ON albums.id = songs.album_id
WHERE year IS NOT null
ORDER BY year DESC
LIMIT 1)
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 5
single
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(SELECT _ _ _
FROM _ _ _
_ _ _ singers
ON _ _ _
_ _ _ albums
ON _ _ _
WHERE _ _ _
ORDER BY _ _ _
LIMIT 1)
UNION ALL
(SELECT _ _ _
FROM _ _ _
_ _ _ singers
ON _ _ _
_ _ _ albums
ON _ _ _
WHERE _ _ _
ORDER BY _ _ _
LIMIT 1)
No query executed yet... |
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal