查询:
SELECT id_user
FROM Rating
Where id_movie=2
INTERSECT
SELECT id_user
FROM Rating
Where id_movie=3
但我明白了:
1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在'INTERSECT SELECT
id_user
FROM Ratingid_movie
= 3 LIMIT 0,30''附近使用正确的语法
任何有解决方案??
答案 0 :(得分:5)
以下查询将执行..
SELECT id_user
FROM Rating
Where id_movie=2 and id_user in
( SELECT id_user FROM Rating Where id_movie=3);
答案 1 :(得分:3)
MySql中缺少Intersect,Minus关键字,解决方法是
请在这里查看
Doing INTERSECT and MINUS in MySQL
我已经给了一个镜头(虽然我是一个SQL Server人员)
<强>输入:强>
id_user id_movie
101 1
102 2
102 3
104 4
102 5
107 6
102 2
103 3
109 9
110 2
110 3
使用交叉(如果在SQL Server中运行)的输出将是
id_user
102
110
MySQL兼容查询
使用Inner join
查询1
select distinct a.id_user
from Rating a
join Rating b on a.id_user = b.id_user
where a.id_movie = 2 and b.id_movie = 3
使用Cross join
查询2
select distinct a.id_user
from Rating a, Rating b
where a.id_user = b.id_user
and a.id_movie = 2
and b.id_movie = 3
使用子查询查询3
上面已经回答过了。
答案 2 :(得分:2)
怎么样:
SELECT r2.id_user
FROM Rating AS r2
JOIN
Rating AS r3
ON r3.id_user = r2.id_user
AND r2.id_movie=2
AND r3.id_movie=3;
这里的想法是你想在评级中加入一行,评分中的另一行,同一用户已经看过电影2和3。