我正在尝试显示一个乐队列表,他们的歌手,专辑名称以及该特定专辑中相应的歌曲数量。
因此,如果乐队A发行了5张专辑,我需要选择(从5张专辑中)他们的专辑中歌曲数量最多的专辑。我有43个乐队,所以我假设(虽然我可能错了)我应该有43行返回。
以下SQL打印乐队的专辑和相应专辑的歌曲数量。
SELECT BAND.NAME AS Band_Name,
MEMBER.NAME AS Singer_Name,
RELEASE.TITLE AS Album_Name,
THESONGS.SONG_NUMBER AS Song_Num
FROM RELEASE, MEMBER, MEMBEROF, BAND,
( SELECT ALLSONGS.RID,
ALLSONGS.NUM AS Song_Number
FROM
( SELECT RELEASE.RID AS RID,
count(SONG.TITLE)AS NUM
FROM RELEASE, SONG
WHERE RELEASE.RID = SONG.RID
GROUP BY RELEASE.RID
ORDER BY COUNT(RELEASE.Title) DESC
) ALLSONGS
) THESONGS
WHERE RELEASE.RID = THESONGS.RID
AND RELEASE.BID = BAND.BID
AND MEMBER.MID = MEMBEROF.MID
AND MEMBEROF.BID = BAND.BID
AND MEMBEROF.INSTRUMENT = 'vocals'
ORDER BY BAND.NAME
我正试图在MAX()
上使用ALLSONGS.NUM
来获取该乐队专辑中最多的歌曲,但收到以下错误:
“column”allsongs.rid“必须出现在GROUP BY子句中或使用 在一个聚合函数“
注意:我只能使用SQL99标准,不能使用IF..ELSE
,COALESCE
等SQL程序。