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 |
|
lesotho72
Starting Member
1 Post |
Posted - 2007-06-06 : 17:52:15
|
| Hello,I am trying to get the price for the MAX (Date) for the following list:SecID Price DateIBM 84.23 1/1/2007IBM 83.21 1/2/2007IBM 85.16 1/3/2007So, SQL should return IBM, 85.16, 1/3/2007I cannot create a stored procedure or function to do this. Must be a view. Looking at derived tables and correlated subqueries. Realize it looks pretty easy. Any help greatly appreciated |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-06-06 : 18:36:20
|
| [code]select T1.SecId, T2.MaxDate, T1.pricefrom YourTable T1Join ( Select SecId, Max(date) MaxDate From YourTable Group by SecId ) T2 On T1.SecId= T2.SecIdand T1.Date = T2.MaxDate[/code]Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-07 : 10:43:08
|
| If you need only record of maximum date, thenSelect top 1 columns from tableorder by date descMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|