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 |
|
GaneshRamanan
Starting Member
40 Posts |
Posted - 2011-02-02 : 06:13:11
|
| Hi,I wants to restrict below rows, i need only 5 rows from Each parameterid based on recent dates. ParameterID Parameter Date SubParameter2 Anaemia 2011/01/28 Yes2 Anaemia 2011/01/27 Yes2 Anaemia 2011/01/26 Yes2 Anaemia 2011/01/25 Yes2 Anaemia 2011/01/24 Yes3 Pedal Edema 2011/02/03 Yes3 Pedal Edema 2011/01/28 Yes3 Pedal Edema 2011/01/27 Yes3 Pedal Edema 2011/01/26 Yes3 Pedal Edema 2011/01/25 Yes3 Pedal Edema 2011/01/24 Yes4 CVS 2011/02/03 Normal4 CVS 2011/01/28 Normal4 CVS 2011/01/27 Normal4 CVS 2011/01/26 Normal4 CVS 2011/01/25 Normal4 CVS 2011/01/24 Normal |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-02-02 : 07:04:13
|
select ParameterID, Parameter, Date, SubParameter from(select row_number() over (partition by ParameterID order by Date DESC) as rownum,* from Your_Table)dtwhere rownum < 6 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
GaneshRamanan
Starting Member
40 Posts |
Posted - 2011-02-02 : 08:31:20
|
| Hi,Thanks for your support.Ganesh |
 |
|
|
|
|
|