你好,我有这个查询,我需要访问子查询内的艺术家ID。但不工作。
SELECT g.name, SUM(l.month_start_value), GROUP_CONCAT(l.artist_id), GROUP_CONCAT(l.month_start_value)
FROM genre g
LEFT JOIN genre_artist ga ON g.id = ga.genre_id
LEFT JOIN artist a ON ga.artist_id = a.id
LEFT JOIN (SELECT artist_id,
(SELECT CAST(value as SIGNED)
FROM platform_information_artist
WHERE platform_information_id =
(SELECT id from platform_information WHERE platform = 'spotify' AND information = 'monthly_listeners')
and artist_id = a.id
AND DATE(date) >= DATE(NOW()) - INTERVAL 30 DAY
ORDER BY date ASC
LIMIT 1) as month_start_value
FROM platform_information_artist
GROUP BY platform_information_artist.artist_id) l ON a.id = l.artist_id
GROUP BY g.id
ORDER BY g.id ASC;
错误的行是and artist_id = a.id
返回此错误:[42S22][1054]“where子句”中的列“a.id”未知
我不知道为什么我不能a.id在子查询中访问www.example.com。
1条答案
按热度按时间j13ufse21#
有很多方法可以做到这一点。对当前查询的最小更改就是简单地更改几个引用:
此版本应在大多数MySQL版本中工作。
如果你使用的是较新版本的MySql,那么你有更多的选择,它们都比上面的方法更有效。第一个是使用横向连接:
另一种方法是使用
ROW_NUMBER()
而不是限制为每个艺术家选择一个值:型
**一个