gpt4 book ai didi

mysql - CoderPad 不支持 SQL 中的排名函数吗?

转载 作者:行者123 更新时间:2023-11-30 21:47:49 26 4
gpt4 key购买 nike

我尝试了以下查询:

select first_name,last_name,salary,rank() over (order by salary) as Rank
from employees
order by Rank

我得到了以下错误:

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 salary) as Rank
from employees
order by Rank at line 1

最佳答案

最简单的实现是row_number(),而不是rank()。也许这对您有用:

select first_name, last_name, salary,
(@rn := @rn + 1) as Rank
from employees e cross join
(select @rn := 0) params
order by salary;

如果您特别需要 rank(),那就有点棘手了。

关于mysql - CoderPad 不支持 SQL 中的排名函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48614504/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com