MySQL时间time类型相减求时长(超详细)

表OD结构:

MySQL时间time类型相减求时长(超详细)_第1张图片

想通过outTime - inTime求得duration

一开始想通过:

mysql> update OD
    -> set duration = outTime - inTime;

来更新,但是报错如下:

Incorrect time value: '9024' for column 'duration' at row 2

自己又试了试只更新一行数据,成功了:

mysql> update OD
    -> set duration = outTime - inTime where passengerID = 1;
Query OK, 1 row affected (0.92 sec)
Rows matched: 1  Changed: 1  Warnings: 0

但是更新第二行时又错了:

mysql> update OD
    -> set duration = outTime - inTime where passengerID = 2;
ERROR 1292 (22007): Incorrect time value: '9024' for column 'duration' at row 2

最后终于找到了解决办法:

mysql> update OD
    -> set duration = timediff(outTime,inTime);
Query OK, 1048387 rows affected (12.03 sec)
Rows matched: 1048575  Changed: 1048387  Warnings: 0

结果:

 MySQL时间time类型相减求时长(超详细)_第2张图片

参考:https://blog.csdn.net/weixin_42550871/article/details/80816646 

https://blog.csdn.net/u013356658/article/details/51849533感谢

 

 

你可能感兴趣的:(MySQL时间time类型相减求时长(超详细))