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 |
DeNam
Starting Member
15 Posts |
Posted - 2013-10-29 : 04:34:21
|
Hi, How can i select row nr (2) from the following table?I want to select distinct ID over first MAX Valid to date and then Valid from date.ID Rating Valid to Valid from5562512136 12 06.07.2013 31.12.20135562512136 9 06.07.2013 31.12.99995562512136 7 06.12.2012 31.12.99995562512136 8 06.07.2013 31.12.2015 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-29 : 05:09:56
|
[code]SELECT ID, Rating, Validto, ValidfromFROM(SELECT *,ROW_NUMBER() OVER (PARTITION BY ID ORDER BY ValidTo DESC, ValidFrom DESC) AS SeqFROM table)tWHERE Seq=1[/code]I assume Validto and Vlidfrom are of datetime datatype------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
DeNam
Starting Member
15 Posts |
Posted - 2013-10-29 : 05:35:15
|
Great, Worked perfect thanks.btw: How do i mark my topics as solved? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-29 : 08:12:05
|
You're welcomeJust append [Solved] to title of topic for that------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|