我收到错误:View的SELECT包含一个带有下面查询的变量或参数。如何创建相同的视图。我非常感谢任何帮助。谢谢你。
CREATE VIEW V AS SELECT @rownum := @rownum + 1 AS rank, name, vote
FROM uservotes, (SELECT @rownum := 0) t ORDER BY vote DESC
答案 0 :(得分:0)
declare @rownum int
CREATE VIEW V AS SELECT @rownum := @rownum + 1 AS rank, name, vote
FROM uservotes, (SELECT @rownum := 0) t ORDER BY vote DESC
答案 1 :(得分:0)
试试这个
CREATE VIEW V AS
(
SELECT (SELECT 1 + COUNT(*) FROM uservotes where votes < T.votes ) AS NUM, name, votes
FROM uservotes T ORDER BY votes DESC
)
您可以定义一个变量以获取伪行号功能,因为MySQL没有任何排名功能:
如果这样做,您将收到1351错误,因为you can't use a variable in a view due to design。 bug/feature behavior is documented here。