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 |
|
bwright611
Starting Member
3 Posts |
Posted - 2004-12-21 : 10:33:53
|
| I have a question similar to the most recent date... What if I need the most recent date for a certain combination.. such as:Person DayOfWeek Achievement AchievementDateBrad Monday Went Out 12/1/04Brad Tuesday Drove 12/14/04Brad Monday Walked 12/5/04Brad Tuesday Talked 12/15/04Sallie Monday Wrote 11/4/04Sallie Monday Drove 12/4/04So the results will be:Person DayOfWeek Achievement AchievementDateBrad Monday Walked 12/5/04Brad Tuesday Talked 12/15/04Sallie Monday Drove 12/4/04Thanks much,BW |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-12-21 : 10:48:35
|
| which combination? Person/DayOfWeek ? What if the data is like this:Mon June 12Tue June 13Wed Apr 5you want to see April mixed in which June's data? If the only Wed in the data occured in a different week, your results might not make much sense. Can you clarify a little more?IN a general sense, to get the latest date for a combo of columns A and B you say:select A,B, Max(Date) as MAxDatefrom YourDatagroup by a,bThat only returns the maximum date, not the entire row that contains the maximum date. to do that, you simply join the above SQL to your original table:select t1.*from YourTable t1inner join (above Sql) t2on t1.A = t2.A and t1.B = t2.Btry it out, expermiment, see if it makes sense.- Jeff |
 |
|
|
bwright611
Starting Member
3 Posts |
Posted - 2004-12-21 : 10:57:53
|
Yeah, I need it for the combination of the Person with the day of the week, so for each person they will have up to 7 latest notes (one for each day). I'm testing out what you gave me now so hopefully this works!Thanks for your help...quote: Originally posted by jsmith8858 which combination? Person/DayOfWeek ? What if the data is like this:Mon June 12Tue June 13Wed Apr 5you want to see April mixed in which June's data? If the only Wed in the data occured in a different week, your results might not make much sense. Can you clarify a little more?IN a general sense, to get the latest date for a combo of columns A and B you say:select A,B, Max(Date) as MAxDatefrom YourDatagroup by a,bThat only returns the maximum date, not the entire row that contains the maximum date. to do that, you simply join the above SQL to your original table:select t1.*from YourTable t1inner join (above Sql) t2on t1.A = t2.A and t1.B = t2.Btry it out, expermiment, see if it makes sense.- Jeff
|
 |
|
|
|
|
|
|
|