如何在SQL中找到两个连续时间戳的区别 [英] How do I find the difference of two consectutive timestamp in my SQL
本文介绍了如何在SQL中找到两个连续时间戳的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须找到两个连续时间戳的区别。但是我在结果集的diff列中得到'NULL'。
什么我试过了:
I have to find the difference of two consecutive timestamp .But I am getting 'NULL' in "diff" column in the resultset.
What I have tried:
SELECT t1.id AS id1,
t2.id AS id2,
t1.timestamp AS timestamp1,
t2.timestamp AS timestamp2,
Timestampdiff(second, t1.timestamp, t2.timestamp) AS diff
FROM logs12 AS t1
JOIN logs12 AS t2 ON (t2.id = t1.id - 1)
推荐答案
按照 SO $的建议c $ c>: php - MySQL:如何以秒为单位获取两个时间戳之间的差异 - Stack Overflow [ ^ ],时间差异功能仅在日期时间小于 35时才有效
相隔天数。看那里提出的解决方案(例如你可以减去 UNIX
时间戳)。
As suggested atSO
: php - MySQL: how to get the difference between two timestamps in seconds - Stack Overflow[^], time diff functions only works when the datetimes are less than35
days apart. See there the proposed solutions (fro instance you could subract theUNIX
timestamps).
这篇关于如何在SQL中找到两个连续时间戳的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文