MySQL Forums
Forum List  »  Quality Assurance

Averaging of values within time restraints
Posted by: kevin kent
Date: November 22, 2011 09:27AM

Hell0,

I have a need to get the average values of a field within user defined time intervals, between user defined datetime's.

Ex.

I need the average of the temperature from 11-20-2011 01:00:00(startDate) to 11-22-2011 1:00:00(endDate), in 2 hour intervals.

So the query would be averaging for 2 hours, then the next 2 hours until it reaches the endDate.

So far I have figured out the problem using php and while loops but I would rather execute this with one query rather than potentially querying the database 1000 times.

So far:

SELECT date_time, AVG(input_calibrated)
FROM inputs
WHERE
(date_time BETWEEN $startDate and $endDate)
AND
(chan_id = $chan_id)

I guess what I really need is a way to get some sort of while loop within the query to run changing the the BETWEEN dates until the endDate is reached.

And direction would be appreciated.

Thank you

Options: ReplyQuote


Subject
Views
Written By
Posted
Averaging of values within time restraints
1543
November 22, 2011 09:27AM


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.