![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Can anyone help with writing a query to find retrieve the start and end dates from a group of dates. For example a record in the table the data will have John MN 1/1/2009 John MN 1/2/2009 John MN 1/3/2009 John MN 1/4/2009 John MN 1/5/2009 John MN 1/6/2009 John CA 1/7/2009 John CA 1/8/2009 John CA 1/9/2009 John CA 1/10/2009 John CA 1/11/2009 Dave WA 2/2/2009 Dave WA 2/3/2009 Dave WA 2/4/2009 Dave WA 2/5/2009 Dave WA 2/6/2009 and I would like to get John MN StartDate 1/1/2009 EndDate 1/6/2009 John CA StartDate 1/7/2009 EndDate 1/11/2009 Dave WA StartDate 2/2/2009 EndDate 2/6/2009 |
#3
| |||
| |||
|
|
RCGUA wrote: Can anyone help with writing a query to find retrieve the start and end dates from a group of dates. *For example a record in the table the data will have John * * MN * * *1/1/2009 John * * MN * * *1/2/2009 John * * MN * * *1/3/2009 John * * MN * * *1/4/2009 John * * MN * * *1/5/2009 John * * MN * * *1/6/2009 John * * CA * * *1/7/2009 John * * CA * * *1/8/2009 John * * CA * * *1/9/2009 John * * CA * * *1/10/2009 John * * CA * * *1/11/2009 Dave * * WA * * *2/2/2009 Dave * * WA * * *2/3/2009 Dave * * WA * * *2/4/2009 Dave * * WA * * *2/5/2009 Dave * * WA * * *2/6/2009 and I would like to get John * MN * StartDate *1/1/2009 * EndDate *1/6/2009 John * CA * StartDate *1/7/2009 * EndDate *1/11/2009 Dave * WA *StartDate *2/2/2009 * EndDate *2/6/2009 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Probably this: SELECT person_name, person_state, MIN(the_date) As StartDate, MAX(the_date) As EndDate FROM table_name GROUP BY person_name, person_state Obviously, change the names to suit your set up. HTH, -- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA) ** Respond only to this newsgroup. *I DO NOT respond to emails ** -----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv iQA/AwUBSnRJ2oechKqOuFEgEQKF/ACfZuIQWbTPAGQQK/BmbGS1NUXXRCQAoI5R uTf6AhokHST92CElam/2v6UW =a50A -----END PGP SIGNATURE------ Hide quoted text - - Show quoted text - |
![]() |
| Thread Tools | |
| Display Modes | |
| |