gpt4 book ai didi

mysql更新列如增量

转载 作者:行者123 更新时间:2023-11-29 16:36:13 25 4
gpt4 key购买 nike

我要更新total_playtime (时间戳),值为 playtime (时间戳)和另一个值,如下所示。

total_playtime = total_playtime + playtime

我使用了以下代码,

UPDATE `user_data` SET `total_playtime`=total_playtime+playtime WHERE id=1

但是此代码仅在以下情况下有效:

>>if second + second, works only when the result is no more than 1 minute. 
for example
00:00:05 + 00:00:10 = 00:00:15 //WORKS
00:00:30 + 00:00:50 = 00:00:00 //DIDNT WORK , it should be 00:01:20

>>if minute + minute, works only when the result is no more than 1 hour
for example
00:05:00 + 00:10:00 = 00:15:00 //WORKS
00:30:00 + 00:50:00 = 00:00:00 //DIDNT WORK , it should be 01:20:00

也就是说,如果结果是从秒转换为分钟,或从分钟转换为小时,则结果为 00:00:00。

我真的很感激一些帮助。谢谢。

最佳答案

这会起作用:

SELECT ADDTIME('00:00:50', '00:00:15');

输出:

00:01:05

输入:

SELECT ADDTIME('00:50:00', '00:30:00');

输出:

01:20:00

对于两个时间戳,您需要执行以下操作:

SELECT ADDTIME(TIME('2008-05-15 13:20:32'),Time('0001-01-01 1:39:27'))

关于mysql更新列如增量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53590344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com