-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-5.sql
40 lines (35 loc) · 867 Bytes
/
query-5.sql
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
35
36
37
38
39
40
/* The identifier of the album that contains the highest number of songs. */
SELECT
ALBUM_SONGS.AlbumId AS "Album"
FROM
ALBUM_SONGS
WHERE
ALBUM_SONGS.TrackId = (
-- Gets the maximum value of TrackId
SELECT
MAX(ALBUM_SONGS.TrackId)
FROM
ALBUM_SONGS
);
/* Without using TrackId attribute */
SELECT
ALBUM_SONGS.AlbumId AS "Album"
FROM
ALBUM_SONGS
GROUP BY
ALBUM_SONGS.AlbumId
HAVING
COUNT(ALBUM_SONGS.SongId) = (
-- Gets the maximum number of songs contained in an album
SELECT
MAX("Tracks")
FROM (
-- Lists the number of songs for every album
SELECT
COUNT(ALBUM_SONGS.SongId) AS "Tracks"
FROM
ALBUM_SONGS
GROUP BY
ALBUM_SONGS.AlbumId
)
);