0

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.

1
  • Wait, no primary key ? I'll assume that e's are unique. If true, then should'nt it be select c,min(s) from words group by c Commented Oct 13, 2014 at 1:58

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.