[英]Using multiple aggregate functions in one SQL query
My table is as below 我的桌子如下
WORKS ( emp-name, comp-name, salary)
I want to find the comp-name which pays to lowest total salary to it's employees 我想找到公司名称,该名称支付给其员工的总薪水最低
I tries below query, but it gives SUM of salaries for all comp-name 我在下面的查询中尝试,但是它给出所有comp-name的薪水总和
SELECT comp-name, MIN(sal) as lowest
FROM
(
SELECT comp-name, SUM(salary) as sal from WORKS group by comp-name
)tmt group by comp-name;
How do I find only one company which pays lowest total salary. 我如何才能找到只有一家公司的工资总额最低。
You can use LIMIT to get only one company with lowest total salary , also need to need to sort in ascending order 您可以使用LIMIT来获得一家总薪水最低的公司,还需要按升序排序
SELECT comp-name,
SUM(salary) as sal
from WORKS
group by comp-name
Order by sal ASC
LIMIT 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.