我有一个名为user
的下面的mysql表 user email count ranking
sss sss@gmail.com 111 0
ss ss@ggmail.con 11 0
s s@gmai.com 1 0
我尝试使用以下mysql qyery来更新排名
SET @r=0; UPDATE table user SET ranking= @r:= (@r+1) ORDER BY count ASC;
但是它给了我错误,我不知道我哪里做错了,任何人都可以帮助我吗?非常感谢!
错误:
SQL query:
UPDATE TABLE user SET ranking = @r := ( @r +1 ) ORDER BY count ASC ;
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table user SET ranking= @r:= (@r+1) ORDER BY count ASC' at line 1
答案 0 :(得分:2)
TABLE
是MySQL reserved keyword。将它用作标识符时将其括在反引号中,但在这种情况下,它是不必要的,应该被删除。
SET @r=0; UPDATE user SET ranking= @r:= (@r+1) ORDER BY count ASC;
请注意,99%的时间,错误消息将指向查询中导致问题的字符或单词。查看错误中'
之后的第一个单词,开始缩小问题范围。
> for the right syntax to use near 'table