Home  >  Article  >  Database  >  mysql每半小时平均值计算的sql语句_MySQL

mysql每半小时平均值计算的sql语句_MySQL

WBOY
WBOYOriginal
2016-05-27 13:45:491321browse

表结构:

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;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn