dbTalk Databases Forums  

find start and end dates from group of consecutive dates

comp.databases.ms-access comp.databases.ms-access


Discuss find start and end dates from group of consecutive dates in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
RCGUA
 
Posts: n/a

Default find start and end dates from group of consecutive dates - 08-01-2009 , 07:24 AM






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

Reply With Quote
  #2  
Old   
MGFoster
 
Posts: n/a

Default Re: find start and end dates from group of consecutive dates - 08-01-2009 , 08:57 AM






RCGUA wrote:
Quote:
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-----

Reply With Quote
  #3  
Old   
RCGUA
 
Posts: n/a

Default Re: find start and end dates from group of consecutive dates - 08-03-2009 , 09:50 AM



On Aug 1, 8:57*am, MGFoster <m... (AT) privacy (DOT) com> wrote:
Quote:
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 -
Yeah MGFoster! Thank You! Your SQL is perfect! It works great.
Below is the SQL with my table names, etc.

SELECT tblDateQ.machineName, Min(tblDateQ.date) AS StartDate, Max
(tblDateQ.date) AS EndDate, tblDateQ.location
FROM tblDateQ
GROUP BY tblDateQ.machineName, tblDateQ.location;

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.