我正在使用此查询并收到错误#1351 - View's SELECT contains a variable or parameter
CREATE VIEW v AS
SELECT name,points,sno ,@rownum := @rownum + 1 AS rank
FROM `users`,(Select @rownum := 0)
GROUP BY name,sno
ORDER BY CAST(points AS UNSIGNED) DESC;
如何使用此方法创建视图?我非常感谢任何帮助。谢谢你。
答案 0 :(得分:1)
假设SNO
在users
表中实际上是唯一的,您可以在没有变量的视图中执行此操作。我不是说你想要,但你可以:
CREATE VIEW v AS
SELECT name,
(select count(*)
from users u2
where u2.points > u.points or
u2.points = u.points and u2.sno <= u.sno
) as rank
FROM `users` u;
答案 1 :(得分:0)
正如CREATE VIEW
Syntax所述:
SELECT
语句不能引用系统或用户变量。