函数内指定是minute,则最终结果value值的单位是分钟,如果函数内指定为hours,则最终结果value值单位为小时。
- //UPLOAD\_TIME 减去 CREATE\_DTTM 求得时间差,以分钟数计时
- select avg(TIMESTAMPDIFF(MINUTE,CREATE\_DTTM,UPLOAD\_TIME)) value,LEFT(CREATE\_DTTM,10) time from 表名
- WHERE
- CREATE\_DTTM >= '2018-01-21'
- AND CREATE\_DTTM <=DATE\_ADD( '2019-02-19',INTERVAL 1 DAY) and UPLOAD\_TIME is not null
- group by LEFT(CREATE\_DTTM,10)
参考:https://blog.csdn.net/yiifaa/article/details/78611079
https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function\_microsecond
- mysql> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');
- -> 3
- mysql> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01');
- -> -1
- mysql> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55');
- -> 128885
原文地址:https://blog.csdn.net/weixin\_38750084/article/details/88118039