Calculate average column value per day

datetime, mysql, sql

Solution

Looks like a simple `AVG` task:

SELECT `datetime`,AVG(`Value`) as AvgValue
FROM TableName
GROUP BY `datetime`

To find average of a specific day:

SELECT `datetime`,AVG(`Value`) as AvgValue
FROM TableName
WHERE `datetime`=@MyDate
GROUP BY `datetime`

Or Simply:

SELECT AVG(`Value`) as AvgValue
FROM TableName
WHERE `datetime`=@MyDate

Explanation:

`AVG` is an aggregate function used to find the average of a column. Read more here.

Problem

I have the following table structure: `Value` (stores random integer values), Datetime` (stores purchased orders datetimes). How would I get the average value from all `Value` rows across a full day? I'm assuming the query would be something like the following ``` SELECT count(*) / 1 FROM mytable WHERE DateTime = date(now(), -1 DAY) ```

Original source