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 |
mlawton
Starting Member
35 Posts |
Posted - 2014-01-30 : 13:13:27
|
I have the following table:StartDate AccountNumber EndDate11/1/2013 1000050005 9/1/201211/1/2013 1000050005 1/19/201311/1/2013 1000050005 1/20/201311/1/2013 1000050005 1/21/201311/1/2013 1000050005 1/22/201311/1/2013 1000050005 1/23/201311/1/2013 1000050005 11/1/201311/1/2013 1000050005 11/2/201311/1/2013 1000050005 11/3/201311/1/2013 1000050005 11/4/201311/1/2013 1000050005 11/5/201311/1/2013 1000050005 11/6/201311/1/2013 1000050005 11/7/201311/1/2013 1000050005 11/8/201311/1/2013 1000050005 11/9/201311/1/2013 1000050005 11/10/201311/1/2013 1000050005 11/11/201311/2/2013 2000100010 7/14/201111/2/2013 2000100010 7/3/201211/2/2013 2000100010 9/1/201211/2/2013 2000100010 12/2/201211/2/2013 2000100010 1/1/201311/2/2013 2000100010 4/2/201311/2/2013 2000100010 5/2/201311/2/2013 2000100010 10/2/201311/2/2013 2000100010 11/1/201311/2/2013 2000100010 11/2/201311/2/2013 2000100010 11/3/201311/2/2013 2000100010 1/1/201411/2/2013 2000100010 1/2/201411/2/2013 2000100010 1/3/201411/2/2013 2000100010 1/4/201411/2/2013 2000100010 1/5/201411/2/2013 2000100010 1/6/2014I want to create a select statement that will return the following results:StartDate AccountNumber EndDate11/1/2013 1000050005 11/11/201311/2/2013 2000100010 1/6/2014I want to return the account number with the maximum date for Endate by startdate.Can this be done?Thanks |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-01-30 : 13:37:22
|
I think this should do what you want:SELECT StartDate, AccountNumber, MAX(EndDate) AS EndDateFROM TableNameGROUP BY AccountNumber StartDate |
|
|
mlawton
Starting Member
35 Posts |
Posted - 2014-01-30 : 13:55:30
|
Thanks!!! This is perfect. |
|
|
|
|
|