我的一个疑问是来自游戏的排名。
查询如下,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'];
答案 0 :(得分:3)
您在SQL Server中使用MySql语法。
使用row_number()
功能重现您当前的逻辑。
SELECT *
FROM (SELECT row_number() OVER (ORDER BY game2points DESC) AS [rank],
totalpoints,
useridFB,
game2points
FROM theuser) AS result
WHERE useridFB = 1234
或者您可能需要调查rank
,具体取决于您希望如何处理关系。