Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to get max of salary for an employee in month

Author  Topic 

spanner21
Starting Member

1 Post

Posted - 2013-11-18 : 01:22:42
hi,

I had two tables where pid is foreign key.

the tables are:

eid ename pid pid salary
now sombody please tell me how to get ename of those who got maximum salary in april month.?

Prav4u
Starting Member

15 Posts

Posted - 2013-11-18 : 03:35:39
hi,
i am assuming you have salarydate column maintained in salary table.
SELECT ename From (
Select ename , DENSE_RANK() over (order by MAX(salary)desc) sr
from employeetable e inner join SalaryTable s on s.Pid = e.Pid
where MONTH(salarydate) = 4
Group by ename , MONTH(salarydate)
)as a
Where sr = 1

hope this helps

Praveen D'sa
MCITP - Database Administrator 2008
http://sqlerrors.wordpress.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-18 : 05:42:46
[code]
SELECT TOP 1 WITH TIES e.ename
FROM salary s
INNER JOIN employee e
On e.pid = s.pid
WHERE s.salarydate >= '20130401'
AND s.salarydate < '20130501'
GROUP BY e.ename
ORDER BY SUM(s.salary) DESC
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -