Challenge: Two Singers
Taak
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.
Oplossing
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)
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 3. Hoofdstuk 5
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... |
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.