gpt4 book ai didi

mysql - 如何计算一个表中不同行和列之间的timestampdiff?

转载 作者:行者123 更新时间:2023-11-29 05:09:13 26 4
gpt4 key购买 nike

我正在尝试计算 statistic 表和 中的结果集的不同行中 end_datetimestart_datetime 之间的时间差暂停时间

我的查询没有执行。

update statistic
set pause_time = TIMESTAMPDIFF(hour, a.start_datetime, b.end_datetime)
from statistic a
inner join statistic b on a.id = (b.id - 1)
order by a.id asc

我收到一个错误:

check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM statistic a INNER JOIN statistic b ON b.id=(a.id - 1) ORDER BY a.id ASC' at line 1 QMYSQL. My table statistic:

<html> <head> <title></title> </head> <body> <div> id<span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp; &nbsp;| &nbsp; &nbsp;start_datetime<span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp; &nbsp; &nbsp;| &nbsp;&nbsp;end_datetime<span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp;pause_time</div> <p> <span style="font-size:12px;">1 <span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp; &nbsp; &nbsp;| &nbsp; &nbsp;2016-10-13T23:14:05<span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp;&nbsp;|&nbsp; <strong><span style="color:#f00;">&nbsp;2016-10-14T07:03:02</span>&nbsp;<span class="Apple-tab-span" style="white-space:pre"> </span></strong>|&nbsp; &nbsp; &nbsp;&nbsp;</span></p> <p> <span style="font-size:12px;">2<span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp; &nbsp; &nbsp; | &nbsp; <span style="color:#f00;"><strong>&nbsp;2016-10-14T15:25:56&nbsp;</strong>&nbsp;</span>| &nbsp;&nbsp;2016-10-14T22:03:50<span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp;|</span></p> <p> <span style="font-size:12px;">3 &nbsp; &nbsp; &nbsp;<span class="Apple-tab-span" style="white-space:pre"> </span>| &nbsp; &nbsp;2016-10-13T15:25:30<span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp; | &nbsp;&nbsp;2016-10-13T22:10:01 &nbsp;|</span></p> <p> <span style="font-size:12px;">4 &nbsp; &nbsp; &nbsp;<span class="Apple-tab-span" style="white-space:pre"> </span>| &nbsp; &nbsp;2016-10-13T01:09:11<span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp; | &nbsp;&nbsp;2016-10-13T02:59:30<span class="Apple-tab-span" style="white-space:pre"> </span>&nbsp;|</span></p> <div> &nbsp;</div>  </body> </html>

最佳答案

您使用的语法是 SQL server 的。

查看 MySQL 的 - https://dev.mysql.com/doc/refman/5.7/en/update.html

试试这个:

update statistic a
join statistic b on a.id = (b.id - 1)
set a.pause_time = TIMESTAMPDIFF(hour, a.start_datetime, b.end_datetime)

关于mysql - 如何计算一个表中不同行和列之间的timestampdiff?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42467916/

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