gpt4 book ai didi

mysql - 错误代码 : 1054 Unknown column in 'where clause'

转载 作者:行者123 更新时间:2023-11-29 00:04:28 25 4
gpt4 key购买 nike

我想获取每个艺术家所有内容的总浏览量

wp_content_details.artist_id = wp_artist.id正在生成错误“Unknown column in where clause” ' 当我使用静态值时 wp_content_details.artist_id = 29那么没关系,但我需要使用条件 wp_content_details.artist_id = wp_artist.id

SELECT wp_artist.id
,wp_artist.NAME
,(
SELECT SUM(total_user) AS total_view
FROM (
SELECT COUNT(DISTINCT (user_id)) AS total_user
FROM wp_views
LEFT JOIN wp_content_details ON wp_content_details.content_id = wp_views.content_id
WHERE wp_content_details.artist_id = wp_artist.id /* Its ok if use: wp_content_details.artist_id = 29*/
AND wp_content_details.role_id = 2
GROUP BY wp_views.content_id
) content_views
) AS total_views
FROM wp_artist
WHERE wp_artist.id IN (
SELECT DISTINCT (wp_content_details.artist_id)
FROM wp_content_details
WHERE wp_content_details.artist_id = wp_artist.id
AND wp_content_details.role_id = 2
)
ORDER BY total_views DESC
,wp_artist.NAME ASC

请帮帮我。如果您有任何困惑,请问我。

最佳答案

wp_artist.ID 超出范围。尝试

    SELECT SUM(total_user) AS total_view
FROM (
SELECT COUNT(DISTINCT (user_id)) AS total_user, wp_content_details.artist_id
FROM wp_views
LEFT JOIN wp_content_details ON wp_content_details.content_id = wp_views.content_id
WHERE wp_content_details.role_id = 2
GROUP BY wp_views.content_id, wp_content_details.artist_id
) content_views
Where content_views.artist_id = wp_artist.id
) AS total_views

关于mysql - 错误代码 : 1054 Unknown column in 'where clause' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28190290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com