sql:mysql:函数:TIMESTAMPDIFF函数实现TimeStamp字段相减,求得时间差

sql:mysql:函数:TIMESTAMPDIFF函数实现TimeStamp字段相减,求得时间差,第1张

sql:mysql:函数:TIMESTAMPDIFF函数实现TimeStamp字段相减,求得时间差

函数内指定是minute,则最终结果value值的单位是分钟,如果函数内指定为hours,则最终结果value值单位为小时。



  1. //UPLOAD_TIME 减去 CREATE_DTTM 求得时间差,以分钟数计时
  2. select avg(TIMESTAMPDIFF(MINUTE,CREATE_DTTM,UPLOAD_TIME)) value,LEFT(CREATE_DTTM,10) time from 表名
  3. WHERE
  4. CREATE_DTTM >= '2018-01-21'
  5. AND CREATE_DTTM <=DATE_ADD( '2019-02-19',INTERVAL 1 DAY) and UPLOAD_TIME is not null
  6. 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


  1. mysql> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');
  2. -> 3
  3. mysql> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01');
  4. -> -1
  5. mysql> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55');
  6. -> 128885

原文地址:https://blog.csdn.net/weixin_38750084/article/details/88118039

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/586844.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存