我必须从 table 工资中找到平均工资最高的部门名称

I have to find the the name of the department with maximum average from the table salary

这是我正在编写但出现错误的代码

select Dep_name,T
from
(select Dep_name,avg(salary) as T
from salary
group by Dep_name) as TT
having max(T);

error: ERROR 1140 (42000) at line 4: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'TT.Dep_name'; this is incompatible with sql_mode=only_full_group_by

一种方法是按平均工资排序,并仅使用 limit 子句排在第一行:

SELECT   dep_name, AVG(salary) 
FROM     salary 
GROUP BY dep_name 
ORDER BY 2 DESC
LIMIT    1