MSSQL:必须声明标量变量@rownum
我的一个疑问是游戏的排名。
查询如下,SQL Server Management Studio 显示的错误是:“必须声明标量变量@rownum”
有什么问题吗?
多谢!
$sql1_1 = "SET @rownum := 0";
$sql2_2 = "SELECT * FROM (
SELECT @rownum := @rownum + 1 AS rank, totalpoints, useridFB, game2points
FROM theuser ORDER BY game2points DESC
) as result WHERE useridFB=1234";
mssql_query($sql1_1);
$result = mssql_query($sql2_2);
$row = mssql_fetch_array($result);
$therank = $row['rank'];
One of my queries is a ranking from a game.
The query is below and the error SQL Server Management Studio shows is: "Must declare the scalar variable @rownum"
what is wrong with it?
Thanks a lot!
$sql1_1 = "SET @rownum := 0";
$sql2_2 = "SELECT * FROM (
SELECT @rownum := @rownum + 1 AS rank, totalpoints, useridFB, game2points
FROM theuser ORDER BY game2points DESC
) as result WHERE useridFB=1234";
mssql_query($sql1_1);
$result = mssql_query($sql2_2);
$row = mssql_fetch_array($result);
$therank = $row['rank'];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在 SQL Server 中使用 MySql 语法。
使用
row_number()
函数重现当前逻辑。或者您可能想要根据您希望如何处理关系来调查
排名
。You are using MySql syntax in SQL Server.
Use the
row_number()
function to reproduce your current logic.Or you might want to investigate
rank
depending on how you want ties to be treated.