这取决于您需要数据的方式。如果您对艺术家更感兴趣,那么您可以加入专辑中的曲目,然后将艺术家加入曲目。这将为您提供每位艺术家的记录。
SELECT
ar.*
FROM albums AS al
JOIN tracks AS t
ON t.album_id = al.album_id
JOIN produced AS p
ON p.produced_track = t.track_id
JOIN artists AS ar
ON ar.artist_id = p.produced_artist
如果您对曲目更感兴趣并且只需要列出艺术家,则执行相同的加入,但在艺术家姓名上使用 group_concat 并按曲目 ID 分组
SELECT
t.*,
GROUP_CONCAT(DISTINCT ar.name ORDER BY ar.name SEPARATOR ', ') AS artists
FROM albums AS al
JOIN tracks AS t
ON t.album_id = al.album_id
JOIN produced AS p
ON p.produced_track = t.track_id
JOIN artists AS ar
ON ar.artist_id = p.produced_artist
GROUP BY t.track_id