-
How to get the highest salary in each grade
Table name: Employee
Column Names: Emp_Code,Emp_name,Grade,Basic
I want to execute an SQL that should give me the highest salary earned by an employees in each grade from the employee table?
Like following:
Emp_Code Emp_Name Grade Basic
-------- -------- ----- -----
AA0701 ALIS A 100000
CE0101 CHRIST B 79500
BJ0601 BOB C 50000
FJ0012 FLORIN D 10000
Thanks in advance
-
Try this
select Emp_Code, Emp_Name, Grade , max(Basic)
from Employee
group by Emp_Code, Emp_Name, Grade
-
Thanx for attending my Query and putting effort to reply it!
I tried but didn't worked up! Gives all Emps. in all the grades with their salary. Can u suggest any other SQL please?
-
If you wanted only the highest paid employee in each grade?
select A.Emp_Code, A.Emp_Name, A.Grade , A.Basic
from Employees A
where exists
(select * from Employees B
Where A.Grade = B.Grade
group by B.Grade
having A.Basic = Max(B.Basic))
-
Simply genious,
It worked the way I wanted it!
Thans alot for your precious advise.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|