sqlite |计算表中的时间戳差

发布于 2025-01-26 12:02:53 字数 389 浏览 2 评论 0原文

我有一个桌子&尝试计算行之间的时间差:

”“在此处输入图像描述”

例如:

Time difference for (rowid: 4) = time (rowid: 3) - time (rowid: 4) = 429168

,其余部分相同。

我该怎么做? 谢谢。

I have a table & trying to calculate time differences between the rows:

enter image description here

For example:

Time difference for (rowid: 4) = time (rowid: 3) - time (rowid: 4) = 429168

And same for the rest.

How could I do that?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳公公是暖光 2025-02-02 12:02:53

对于每一行,您可以使用lag()窗口函数来获取上一行的时间:

LAG(time) OVER (ORDER BY id)

或:

LAG(time, 1, ?) OVER (ORDER BY id)

在哪里替换time在没有以前的行时获得。
SQL语句应为:

SELECT *, 
       LAG(time) OVER (ORDER BY id) - time AS difference
FROM tablename;

For each row you can get the previous row's time with LAG() window function:

LAG(time) OVER (ORDER BY id)

or:

LAG(time, 1, ?) OVER (ORDER BY id)

where you replace ? with the time that you want to get when there is no previous row.
The sql statement should be:

SELECT *, 
       LAG(time) OVER (ORDER BY id) - time AS difference
FROM tablename;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文