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;