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 |
|
patshaw
Posting Yak Master
177 Posts |
Posted - 2009-03-23 : 14:07:47
|
| Hi,I have a table:ContactFK INT, DateOfCall DateTimewhich holds about 10k rows and links back to the Contact table via ContactFK on a one to many. Based on the DateofCall, I need to find the second and third most recent DateofCall for each ContactFK but am struggling to do this. Can anyone offer any help please? |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-03-23 : 14:14:10
|
| Can you try this...select t.ContactFk,t.DateCall from (select row_number () over (partition by ContactFk order by DateCall desc) as rn, * from @t) t where t.rn in(2,3) |
 |
|
|
|
|
|