我尝试在单个查询中更新用户的排名,但它因以下错误而崩溃:
ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE users SET rank = @r:= (@r+1) ORDER BY score DESC' at line 1
我的查询有什么问题吗?
SET @r=0;UPDATE users SET rank = @r:= (@r+1) ORDER BY score DESC
我收到来自 this answer 的查询
我正在 node.js mysql library 上执行此查询.
db.query('SET @r=0;UPDATE users SET rank = @r:= (@r+1) ORDER BY score DESC', function(err){
if (err){
console.log(err);
return;
}
console.log("Ranking updated successfully.");
});
最佳答案
怎么样:
SET @r=0;UPDATE users SET rank = (@r+1) ORDER BY score DESC
我不确定您为什么要再次重新分配变量。
关于mysql - 更新用户等级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45736395/