doumindang2416 2012-10-07 14:33
浏览 20
已采纳

Mysql Php温度读数的平均值除以小时

I have a MYSQL DB with two columns, one is the temperature and the other one is the time in which the temperatura was read, like http://pastebin.mozilla.org/1860064 . The temperature USUALLY have a 5minutes difference between reads, but this is not always with this time gap.

What I need to figure out is a algorithm to read all the values and save the average of every hour of read, so temperature will be saved on the db with one temperature per hour, 24 reads per day, and it would save in another db's table.

For example:

enter image description here

It would save with the average temperature and with the date 2012-10-07 10:00:00,

Was I clear?

  • 写回答

2条回答 默认 最新

  • dtuqxb3884 2012-10-07 15:03
    关注

    Here is one way to do this with just a query. If you need the results stored in the database you'll need your own inserts but this will get you the data you're looking for.

    SELECT AVG(temperature),HOUR(read_time) as read_hour FROM temperature_reads WHERE DATE(read_time) = '2012-10-06' GROUP BY read_hour
    

    You can swap the 2012-10-06 part out for whatever date you are looking at.

    Edit: Here it is updated with your info:

    SELECT AVG(temperatura),HOUR(data) as read_hour FROM leituras WHERE DATE(read_time) = '2012-10-06' GROUP BY read_hour
    

    This should do the trick!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算