我想更新用户的排名在一个单一的查询,但它崩溃,出现此错误:更新用户排名
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.");
});
你在哪儿执行这条语句?直接在命令行或编程语言中? – Yannici
@Yannici更新的问题代码 – user234