Reputation: 11032
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
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.
Upvotes: 0
Views: 762
Reputation: 13425
You can use LIMIT to get only one company with lowest total salary , also need to need to sort in ascending order
SELECT comp-name,
SUM(salary) as sal
from WORKS
group by comp-name
Order by sal ASC
LIMIT 1
Upvotes: 1