我试图返回用户a和b有共同点的普通电影的计数。当我试图把结果限制在 num >= 50
. 我收到一个错误“表别名或列引用'num'无效”。
我需要使用相关子查询吗?
如果我有,你能举个例子吗。
SELECT
a.user_id, b.user_id, count(*) AS num, collect_set(m.movie_title)
FROM
ratings a
JOIN
ratings b
ON
(a.movie_id = b.movie_id)
JOIN
movies m
ON
(a.movie_id = m.movie_id AND b.movie_id = m.movie_id)
WHERE
(a.user_id <> b.user_id AND num >= 50)
GROUP BY
a.user_id, b.user_id;
1条答案
按热度按时间wvt8vs2t1#
只需添加
HAVING count(*)>=50
过了一段时间GROUP BY