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 |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2011-01-11 : 19:30:48
|
| Hi GuysNeed help writing a query to get only top3 claim numbers for members based on service date.Sample DataMemberid Claimno Service date1 xyz 1/1/20101 xcz 1/3/20101 xcv 1/5/20101 xbn 1/7/20101 xmn 2/9/20102 zxc 4/1/20102 zvb 5/1/2010trying to write a query so that just the top 3 claim numbers are retreived for all the members based on the service dateMemberid Claimno Service date1 xmn 2/9/20101 xbn 1/7/20101 xcv 1/5/20102 zop 8/1/20102 zmk 7/1/20102 znm 6/1/2010 |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2011-01-11 : 19:44:43
|
| [code]select memberid, claimno, servicedatefrom(select memberid, claimno, servicedate, row_number() over (partition by memberid order by servicedate desc) as rnfrom yourtable) awhere rn <= 3[/code] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|