我有关系讲师(ID,姓名,dept_name,薪水)。
我如何找到平均工资最高的部门名称?
答案 0 :(得分:3)
看起来像HAVING子句的作业
答案 1 :(得分:1)
会这样做吗?
select top 1 id, name, avg (salary)
from instructor
group by id, name
order by avg (salary) desc
答案 2 :(得分:0)
鉴于 homework 标签,我不会为您拼出,但您想查看AVG
函数和GROUP BY
子句。
答案 3 :(得分:0)
select top 1 dept_name, avg(salary) as AvgSalary
from instructor
group by dept_name
order by AvgSalary desc
答案 4 :(得分:0)
如果两个部门的平均工资相同,这将使你们两个,如果不需要,则使用rownum = 1.
with averages as (select dept_name,avg(salary) aver from instructor group by dept_name)
select dept_name
from averages
where aver = (select max(aver) from averages)