我有以下数据库
我想选择包含大多数AC / DC歌曲的播放列表,但我的脚本不起作用。
我的剧本:
SELECT playlist.Name
FROM playlist
INNER JOIN playlisttrack
ON playlist.PlaylistId = playlisttrack.PlaylistId
INNER JOIN track
ON playlisttrack.TrackId = track.TrackId
INNER JOIN album
ON track.AlbumId = album.AlbumId
WHERE ArtistId = 1;
答案 0 :(得分:0)
自从我完成MySql以来已经有一段时间了,但它应该非常接近这一点。
SELECT playlist.Name
FROM playlist
INNER JOIN playlisttrack
ON playlist.PlaylistId = playlisttrack.PlaylistId
INNER JOIN track
ON playlisttrack.TrackId = track.TrackId
INNER JOIN album
ON track.AlbumId = album.AlbumId
WHERE album.ArtistId = 1
GROUP BY playlist.PlayListId, playlist.Name
ORDER BY COUNT(*) DESC
LIMIT 1;
请注意,Group By
将您的播放列表混为一谈(我包括PlayListId,因为您没有做任何表示您的姓名是唯一的)
我正在ORDER BY COUNT(*) DESC
进行每个播放列表中的计数,然后我执行LIMIT 1
来获得第一个。