我正在使用 JSF 2 做一个项目,并且我有一个特别复杂的查询来提供电影建议。我试图把它作为一个命名查询,编译器告诉我有一个错误,老实说我不知道在哪里看
SELECT M.*
FROM Account A,
Movie M,
Orders O,
Rental R,
(SELECT Acc.Id
FROM Account Acc,
(SELECT COUNT(*) AS c,
Acc.Id
FROM Account Acc,
(SELECT M.*
FROM Account A,
Rental R,
Orders O,
Movie M
WHERE A.Id=R.AccountId
AND R.MovieId=M.Id
AND R.OrderId=O.Id
AND A.Id=:id) AS a
INNER JOIN
(SELECT M.*,
A.Id AS AccountId
FROM Account A,
Rental R,
Orders O,
Movie M
WHERE A.Id=R.AccountId
AND R.MovieId=M.Id
AND R.OrderId=O.Id
AND A.Id<>:id) AS b USING (Id,Name,TYPE,Rating,DistrFee,NumCopies)
WHERE Acc.Id = b.AccountId ) AS COUNT
WHERE COUNT.c>0
AND COUNT.Id = Acc.Id) AS SimilarAccount
WHERE A.Id=R.AccountId
AND R.MovieId=M.Id
AND R.OrderId=O.Id
AND A.Id=:id
AND M.Id NOT IN
(SELECT M.Id
FROM Account A,
Rental R,
Orders O,
Movie M
WHERE A.Id=R.AccountId
AND R.MovieId=M.Id
AND R.OrderId=O.Id
AND A.Id=SimilarAccount.Id)
除了性能问题(教授希望通过 MySQL 完成电影建议),我不确定存储此查询以供重复使用的过程。我会将查询存储为视图,但它有一个参数(它需要用户的参数 id)
您建议如何存储此查询?