select *from prof where sal=(select max(sal) from prof)
这种嵌套查询可以查询老师最高工资的全部信息
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
select name from table where salary = (select max(salary) from table);
答: select max(salary) from table 这句话就是取出公司所有人员的最大工资
select pn,name,dn,sal from prof where pn in (select pn,dn,max(sal) from prof group by pn,dn)
一楼如果每个系最高工资有两人或者更多的人怎么办?
一楼正解,不过两个表的别名搞混了
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