MySQL Forums
Forum List  »  Newbie

Re: Help with SQL statement
Posted by: David Fells
Date: March 23, 2005 04:38PM

SELECT
d1.TrainerID, d1.Date as startDate, d2.Date as endDate
FROM
details AS d1, details AS d2
WHERE
(d1.Date < d2.Date) AND
NOT EXISTS (SELECT * FROM details AS d3, details AS d4
WHERE (
d3.Date <= d4.Date AND
d4.Date = DATE_SUB(d3.Date, INTERVAL 1 DAY) AND
d3.Date BETWEEN DATE_ADD(d1.Date, INTERVAL 1 DAY) AND d2.Date)
OR (
d3.Date = DATE_SUB(d1.Date, INTERVAL 1 DAY) AND d3.Date < d1.Date)
OR (
d3.Date = DATE_ADD(d2.Date, INTERVAL 1 DAY) AND d3.Date > d2.Date))
GROUP BY
TrainerID


That should do it, I think...

Options: ReplyQuote


Subject
Written By
Posted
March 23, 2005 08:00AM
Re: Help with SQL statement
March 23, 2005 04:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.