sql查询最高工资的人

2025-03-22 19:03:08
推荐回答(5个)
回答(1):

select *from prof where sal=(select max(sal) from prof)
这种嵌套查询可以查询老师最高工资的全部信息

回答(2):

select a.dn,a.pn,a.name, a.sal
from
(--- 1、获取每个系最高的工资
select dn,max(sal) as maxsal 
from prof
group by dn
)a --2、通过系名/最高工资再与教职工表进行关联
left join prof b on a.dn=b.dn and a.sal=b.maxsal

回答(3):

select name from table where salary = (select max(salary) from table);
答: select max(salary) from table 这句话就是取出公司所有人员的最大工资

回答(4):

select pn,name,dn,sal from prof where pn in (select pn,dn,max(sal) from prof group by pn,dn)

一楼如果每个系最高工资有两人或者更多的人怎么办?

回答(5):

一楼正解,不过两个表的别名搞混了

SELECT b.pn, b.name, b.dn, a.maxsal
FROM (SELECT dn, MAX(sal) AS maxsal FROM prof
GROUP BY dn) AS a INNER JOIN prof AS b ON a.dn = b.dn AND a.maxsal = b.sal