SELECT
FORMAT(SUM(e.salary),0) as sumOfSalary,
d.departName
FROM
employee e
JOIN depart d on (d.id = e.depart)
GROUP BY d.departName
ORDER BY sumOfSalary desc
SELECT
FORMAT(SUM(e.salary),0) as sumOfSalary,
d.departName
FROM
employee e
JOIN depart d
on (d.id = e.depart)
GROUP BY d.departName
ORDER BY sumOfSalary desc
LIMIT 1
select departName, format(max(sumOfSalary),0) from
(SELECT
SUM(e.salary) as sumOfSalary,
d.departName
FROM
employee e
JOIN depart d on (d.id = e.depart)
GROUP BY d.departName
ORDER BY SUM(e.salary) desc limit 1) as nested
SELECT FORMAT(MAX(sumOfSalary),0) FROM (
SELECT
SUM(e.salary) as sumOfSalary, d.departName
FROM employee e
JOIN depart d on d.id = e.depart)
GROUP BY d.departName
) AS ss
3条答案
按热度按时间hpxqektj1#
使用limit仅返回查询的顶部结果:
slmsl1lt2#
当您使用格式时,结果不是按数字值排序的,而是按字母顺序排列的,所以“600”按降序排在“3000”之前
vh0rcniy3#
如果你只需要所有部门中的最高工资(我希望我正确地回答了你的问题!),然后使用嵌套查询: