我想每2秒获取一次数据并获得平均数据(如果它们有相同的时间)。
例如:
Number value Time
[ 1] [20.1000] '2014-04-07 17:11:04'
[ 2] [20.2000] '2014-04-07 17:11:05'
[ 3] [20.3000] '2014-04-07 17:11:05'
[ 4] [20.4000] '2014-04-07 17:11:06'
[ 5] [20.5000] '2014-04-07 17:11:06'
结果应该是这样的。 :
Number Value Time
[ 1] [20.1000] '2014-04-07 17:11:04'
[ 4] [20.4500] '2014-04-07 17:11:06'
我只是尝试每2秒钟获取一次数据而不使用..
进行平均SELECT number,value,time FROM testdata WHERE time BETWEEN 17:00:00 AND 18.00:00
GROUP BY second(time) DIV 2
但是,它并没有给我带来好成绩。
谢谢。
答案 0 :(得分:0)
没有测试,这样的事情应该这样做: -
SELECT `Time`, MIN(Number), AVG(value)
FROM testdata
WHERE TIME(`Time`) BETWEEN '17:00:00' AND '18.00:00'
AND MOD(UNIX_TIMESTAMP(`Time`), 2) = 0
GROUP BY `Time`