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以上

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

 

posted @ 2021-03-10 18:01  wujingqi  阅读(127)  评论(0编辑  收藏  举报