sql查出每个部门高于部门平均工资的前五条数据

2025年03月22日 20:36
有4个网友回答
网友(1):

with table_a as (
select deptno,avg(sal) avgsal from emp
)
select a.* from emp a inner join dept b on a.deptno=b.deptno inner join table_a c on a.deptno=c.deptno
and a.sal>c.avgsal

网友(2):

mysql 不支持top命令,但支持limit命令
即 如: select * from table where a>b order by c limit 5.
即为 取出 符合条件a>b的按照C排序的前5条记录

网友(3):

在所有字段前,select后加上top 5

网友(4):

top 取前几条的 你可要试试