开发者

MySQL: daily average value

开发者 https://www.devze.com 2023-01-09 01:00 出处:网络
I have a table with a \'timestamp\' column and a \'value\' column where the values are roughly 3 secon开发者_如何学JAVAds apart.

I have a table with a 'timestamp' column and a 'value' column where the values are roughly 3 secon开发者_如何学JAVAds apart.

I'm trying to return a table that has daily average values.

So, something like this is what i'm looking for.

| timestamp  | average |
| 2010-06-02 |  456.6  |
| 2010-06-03 |  589.4  |
| 2010-06-04 |  268.5  |
etc...

Any help on this would be greatly appreciated.


SELECT DATE(timestamp), AVG(value)
FROM table
GROUP BY DATE(timestamp)

Since you want the day instead of each timestamp


 select DATE(timestamp), AVG(value)
 from TABLE
 group by DATE(timestamp)


This assumes that your timestamp column only contains information about the day, but not the time. That way, the dates can be grouped together:

select timestamp, AVG(value) as average
from TABLE_NAME
group by timestamp
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号