Error Code: 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...

Error Code: 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 'Rank FROM (SELECT DISTINCT Score FROM Scores order by Score) s ,(SELECT @i:=0) ' at line 1

 一直以为语法错了,但又不知道哪错了,

SELECT  s.Score AS Score,(@i:=@i+1) AS Rank  FROM (SELECT DISTINCT Score FROM Scores ORDER BY Score) s ,(SELECT @i:=0) t;

最后查到rank是MySQL版本8.0.2中定义的MySQL保留字。因此,不能将rank用作列名。你需要在排名周围使用反勾号。

我的mysql版本正好是8以上

做题时候都提示了,我都没在意。

原文地址:https://www.cnblogs.com/wjq-/p/14513365.html