MySQL Forums
Forum List  »  PHP

Re: nested select statement syntax error
Posted by: Peter Brawley
Date: July 17, 2006 07:58AM

To join to a range of dates you need a calendar table with one row per day. For a simple way to build such a table, have a look at 'Make a calendar table' at http://www.artfulsoftware.com/queries.php. Then to query for this past May you would write something like ...

SELECT c2.date, MAX(c2.recv-c1.recv) AS MaxDiff
FROM calendar AS cal
INNER JOIN cells AS c1 ON cal.date=DATE(c1.date)
INNER JOIN cells AS c2 ON TIME_TO_SEC(TIMEDIFF(c2.date,c1.date))<=7*60 AND c2.date>c1.date
WHERE YEAR(cal.date)=2006 AND MONTH(cal.date)=5
GROUP BY cal.date;

PB

Options: ReplyQuote




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.