奥利凡德的库存挑战:在 Mysql 编译器中显示语法错误时出错 row_number() over(分区依据 )


select id,
age,
coins_needed,
power
from(select wands.id as id,
wands.code as code,
wands_property.age as age,
wands.coins_needed as coins_needed,
wands.power as power,
wands_property.is_evil as is_evil,
row_number() over(partition by wands.code,wands.power order by wands.code,wands.power,wands.coins_needed) as rownum
from wands inner join wands_property
on wands.code = wands_property.code
order by wands.code,wands.power) sub
where is_evil = 0 and rownum = 1
order by 4 DESC,2 DESC

我正在解决一个挑战在黑客排名,我不得不使用row_number()和在黑客排名的MySQL编译器有一个语法错误如下:-

ERROR 1064 (42000) at line 1:你的SQL语法有一个错误;请查看与MySQL服务器版本对应的手册使用near '(由wand .code,wand . net划分)的正确语法。权力秩序由wands.power wands.code魔杖。第11行

我在MySQL工作台中尝试了相同的查询,令我惊讶的是查询正在运行并且没有显示任何错误。谁能给我解释一下真正的问题是什么?

ERROR 1064 (42000) at line 1:你有一个SQL语法错误;请查看与MySQL服务器版本对应的手册使用near '(通过....分区)的正确语法第11行

如果你得到这个错误,那么它可能是你运行在旧的mysql/mariadb

MySQL/MariaDB从8.0版本和10.2版本开始引入ROW_NUMBER()函数和其他窗口函数。

最新更新