SELECT sec_to_time(AVG(time_to_sec(time))) from
select left(`时间`,10),`类型`,avg(`排名`) from tablename group by left(`时间`,10),`类型` order by left(`时间`,10),`类型`select DATE_FORMAT(`时间`,%Y-%m-%d) ,`类型`,avg(`排名`) from tablename group by DATE_FORMAT(`时间`,%Y-%m-%d) ,`类型` order by DATE_FORMAT(`时间`,%Y-%m-%d) ,`类型`
函数UNIX_TIMESTAMP(createtime)把时间转换成UNIX时间戳,也就是与1970年1月1日的秒数差,因为你是要求按每分钟,所以DIV 60把秒转换成分钟,通过GROUP BY把数据分组,用AVG函数求出每个分组的平均值。SELECT (UNIX_TIMESTAMP(createtime) DIV 60)
, AVG(dustquantity) AS dustquantity
, AVG(indoortemperature) AS indoortemperature
, AVG(indoorhumidity) AS indoorhumidity
, AVG(carbondioxide) AS carbondioxide
, AVG(voc) AS voc
FROM 表名
GROUP BY UNIX_TIMESTAMP(createtime) DIV 60
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)