我有一个问题:
SELECT b.user_id FROM users b where b.ratings_count !=
(SELECT COUNT(*) FROM
( SELECT wi.id FROM winelist_items wi
JOIN wine_rated wr
ON rate_user_id = b.user_id
AND rate_vintage_id = wi.vintage_id
AND wi.winelist_id = (SELECT id FROM winelist w
WHERE w.user_id = b.user_id LIMIT 1 )
AND wi.vintage_id !=0
)t
) limit 10;
必须从与计算的列中的列中具有不同ratings_count的用户中选择所有user_id 通过sql。但问题是我收到了错误消息'错误代码:1054。未知栏' b_user_id'在' on条款' &#39 ;.我是什么 做错了?非常感谢您的帮助。
答案 0 :(得分:1)
尝试这个
SELECT b.user_id,
(SELECT count(wi.id)
FROM wine_rated wr
JOIN winelist_items wi ON wr.rate_vintage_id = wi.vintage_id
WHERE wr.rate_user_id = b.user_id
AND wi.winelist_id =
(SELECT id
FROM winelist w
WHERE w.user_id = wi.rate_user_id LIMIT 1)
AND wi.vintage_id !=0 ) AS CNT
FROM users b
GROUP BY b.user_id HAVING b.ratings_count !=CNT LIMIT 10;