当我在MySQL中运行下面的SQL查询时
select distinct city, length(city) from station order by length(city), order by city asc limit 1;
我的错误是因为
ERROR 1064 (42000) at line 1: 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 'order by city asc limit 1' at line 1
我不明白我在哪里犯的错
只允许一个ORDER BY,然后用逗号分隔列名,如
order by length(city), city asc
您有两次order by
。 想必你想:
select distinct city, length(city)
from station
order by length(city), city asc
limit 1;
也就是说,单个order by
可以有多个键。