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.
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 salarynow 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 = 1hope this helpsPraveen D'saMCITP - Database Administrator 2008http://sqlerrors.wordpress.com |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-18 : 05:42:46
|
[code]SELECT TOP 1 WITH TIES e.enameFROM salary sINNER JOIN employee eOn e.pid = s.pid WHERE s.salarydate >= '20130401'AND s.salarydate < '20130501'GROUP BY e.enameORDER BY SUM(s.salary) DESC[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|