表结构:
CREATE TABLE `instance` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `timestamp` int(10) unsigned DEFAULT NULL, `cpu` decimal(8,3) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB;
统计每半小时平均值,实现可以如下:
select `timestamp`-`timestamp`% (5*60) , avg(cup) from `instance` group by `timestamp`-`timestamp`% (5*60)
另外还有:
SELECT queueName, HOUR(dt) AS h, FLOOR(MINUTE(dt) / 30) AS v , avg(memoryUsed), sum(memoryUsed), count(memoryUsed) from queue_resource where dt>='2014-04-14 00:00:00' GROUP BY h, v, queueName;本博客文章除特别声明,全部都是原创!
原创文章版权归过往记忆大数据(过往记忆)所有,未经许可不得转载。
本文链接: 【mysql每半小时平均值】(https://www.iteblog.com/mysql%e6%af%8f%e5%8d%8a%e5%b0%8f%e6%97%b6%e5%b9%b3%e5%9d%87%e5%80%bc/)
厉害,用到了您的代码