mysql每半小时平均值计算的sql语句
表结构:
CREATETABLE`instance`( `id`int(11)unsignedNOTNULLAUTO_INCREMENT, `timestamp`int(10)unsignedDEFAULTNULL, `cpu`decimal(8,3)DEFAULTNULL, PRIMARYKEY(`id`) )ENGINE=InnoDB;
统计每半小时平均值,实现可以如下:
select`timestamp`-`timestamp`%(5*60),avg(cup) from`instance` groupby`timestamp`-`timestamp`%(5*60)
另外还有:
SELECTqueueName,HOUR(dt)ASh,FLOOR(MINUTE(dt)/30)ASv, avg(memoryUsed),sum(memoryUsed),count(memoryUsed) fromqueue_resource wheredt>='2014-04-1400:00:00' GROUPBYh,v,queueName;