P粉3478048962023-09-06 10:33:08
使用此 UNIX_TIMESTAMP
转换为秒,然后使用 FROM_UNIXTIME
将其恢复为日期时间格式,这就是获取平均值的方法:
select id, FROM_UNIXTIME(AVG(UNIX_TIMESTAMP(`time`))) from timestamp_n_datetime group by id;
这是填充平均值的方法:
update timestamp_n_datetime td inner join ( select id, FROM_UNIXTIME(AVG(UNIX_TIMESTAMP(`time`))) as average from timestamp_n_datetime group by id ) as s on s.id = td.id set avg_time = s.average;