I have a temperature table, which contains a DATETIME field and a temperature field which is type of float. There are temperature measurements taken every 30 minutes so it’s 48 times a day. What I want to do is to select a date range (eg. 2012-01-01 to 2012-05-01), calculate each day’s average temperature and return the average temperature of each day in the range. Solutions?
Thanks
Use
DATE()to strip off the time portion of the datetime field, and use it in theGROUP BYclause for the aggregateAVG()of the temperature column. YourWHEREclause will filter the date range you want to find.Note: From your description, it sounds like every day does have readings, but if any day does not appear in your readings table, it will be absent from your result set here.