GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Jan-2005, 15:36
rams rams is offline
New Member
 
Join Date: Jan 2005
Posts: 10
rams is on a distinguished road

Subquery


I need the get a rolling 30 day average, so for each day I need to get a average of the 30 days before it. The following works in Microsoft Access, but I can't get it to work with MySQL and PHP, any ideas:

SELECT tbldailydatal1.Date, Avg(tbldailydatal1_1.MetalTap/tbldailydatal1_1.Pots) AS 30DayPPD
FROM tbldailydatal1, tbldailydatal1 AS tbldailydatal1_1
WHERE (((tbldailydatal1_1.Date) Between DateAdd("d",-30,[tbldailydatal1].[Date]) And [tbldailydatal1].[Date]))
GROUP BY tbldailydatal1.Date
HAVING (((tbldailydatal1.Date) Between #9/1/2004# And #1/25/2005#));

Any suggestions?
  #2  
Old 28-Jan-2005, 03:55
besttoolbars
 
Posts: n/a
Isn't DateAdd() a specific Access function?
  #3  
Old 28-Jan-2005, 09:34
rams rams is offline
New Member
 
Join Date: Jan 2005
Posts: 10
rams is on a distinguished road
I'm referencing a file that creates a DateAdd funtion for MySQL. The following works when I take of the "Having" clause, but I need to limit the data to a specific date range, any suggestions?

$SQLstatement = "Select UNIX_TimeStamp(t1.Date), Avg(t2.MetalTap/t2.Pots) AS DayPPD
From tbldailydatal1 as t1, tbldailydatal1 as t2
WHERE t2.Date between 'DateAdd(d,-30,t1.Date)' and t1.Date
GROUP BY t1.Date
HAVING t1.Date Between '$Selectedstart' and '$Selectedend'";
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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 Off
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:24.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.