每分钟mysql平均值参考unix时间戳 [英] Mysql average value every minute refer to unix timestamp

查看:110
本文介绍了每分钟mysql平均值参考unix时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用unix时间戳每1-3秒记录一次温度,希望平均每1分钟获取一行数据并持续24小时.

I logging my temperature every 1-3 seconds with unix timestamp, I wish like get row of data return by average every 1 minute period and last for 24 hour.

我的记录器表如下:

unixtime    temp
1350899052  25.37
1350899054  25.44
1350899057  25.44
1350899059  25.44
1350899062  25.44
1350899064  25.44
1350899069  25.44
1350899071  25.44

我希望它返回为

unixtime    temp
1350899052  25.37 -- average value of 1 minute range both unixtime and temp 
1350899054  25.44
1350899057  25.44

请告知我应该如何执行mySQL命令?谢谢.

please advise how is mySQL command should i do ? thank.

推荐答案

以下方法应该起作用:

SELECT ROUND(unixtime/(60))以分钟为单位,平均(temp)FROM表,其中unixtime> = UNIX_TIMESTAMP(DATE_SUB(NOW(),INTERVAL 1 DAY))GROUP BY ROUND(unixtime/(60));

以常规格式显示日期:

SELECT from_unixtime(floor(unixtime/(60))* 60)以分钟为单位,平均距测试平均时间(unixtime> = UNIX_TIMESTAMP(DATE_SUB(NOW(),INTERVAL 1 DAY)))(unixtime/(60))

输出:

minute  avg(temp)
2012-10-24 08:02:00 37.5
2012-10-24 08:03:00 45

这篇关于每分钟mysql平均值参考unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆