|
sqldba20
Posting Yak Master
183 Posts |
Posted - 2011-03-07 : 11:58:27
|
| Folks:I have the data in a table in following format. I would like to get the data (Name, Date, Value) for the second max (largest) date.TABLE DATA:NAME, DATE, ValueABC,3/3/2011,4ABC,3/4/2011,5ABC,3/3/2011,6ABC,3/5/2011,6ABC,3/7/2011,7ABC,3/7/2011,3XYZ,3/7/2011,3XYZ,3/6/2011,4PQR,3/1/2011,3PQR,3/2/2011,7PQR,3/2/2011,4PQR,3/5/2011,4PQR,3/5/2011,3PQR,3/4/2011,2OUTPUT SHOULD BE :ABC,3/5/2011,6XYZ,3/6/2011,4PQR,3/4/2011,2How will be my query be?Thanks ! |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-07 : 12:15:59
|
| select *from( select Name,Date,Value ,[aRank] = dense_rank() over(partition by name order by date desc) from data) twhere t.arank = 2JimP.S. do you really have a table with those column names?!Everyday I learn something that somebody else already knew |
 |
|