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 |
scabral7
Yak Posting Veteran
57 Posts |
Posted - 2012-09-11 : 23:06:40
|
Hi,I have the following table:Occ_Num Feature_Num Trans_Date Peril_Desc123 1 1-2-2012 Water123 1 1-11-2012 Ice123 2 1-2-2012 Other123 2 1-13-2012 Other123 2 1-19-2012 WindI want to select each Occ_Num, Feature_NUM, Trans_Date, and PERIL_Desc but with only the Peril that was part of the max trans_date.So i would want the following from above:Occ_Num Feature_Num Trans_Date Peril_Desc123 1 1-11-2012 Ice123 2 1-19-2012 WindI'm having trouble with the syntax need to accomplish this. |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-09-11 : 23:17:56
|
[code]select *from( select *, rn = row_number() over (partition by Occ_num order by Trans_Date desc) from yourtable) dwhere d.rn = 1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|