Mysql 如何从表中检索5个最高值
我有一张10行的表格,上面有员工id和工资。 我想要一张5行的桌子,按最高工资的顺序排列Mysql 如何从表中检索5个最高值,mysql,Mysql,我有一张10行的表格,上面有员工id和工资。 我想要一张5行的桌子,按最高工资的顺序排列 create table employee( id int not null primary key, employeeName VarChar(20), salary int ); 谢谢。您可以使用秩、密秩或行号 例如: select * from ( select *, rank() over(order by salary desc) as rk from employee ) x
create table employee(
id int not null primary key,
employeeName VarChar(20),
salary int
);
谢谢。您可以使用秩、密秩或行号
例如:
select *
from (
select *,
rank() over(order by salary desc) as rk
from employee
) x
where rk <= 5
order by rk, employeename
请参阅运行示例,其中显示了6行,因为其中两行并列第五。SELECT*FROM employee ORDER BY salary DESC LIMIT 5哪个版本的MySQL?5.x还是8.x?@员工如何检查?领带会怎么样?例如,如果有两三名员工并列第五?您想要全部还是随机一个?选择版本;