我只想在超过2分钟的时间内用TIMEDIFF显示结果
表:
dt session_id
2016-11-15 11:25:00 1
2016-11-15 11:21:04 1
2016-11-15 11:20:00 1
2016-11-15 09:37:00 2
2016-11-15 09:27:00 2
2016-11-14 21:37:00 3
2016-11-14 21:33:35 3
2016-11-14 21:31:00 3
2016-11-14 16:05:00 4
2016-11-14 16:04:35 4
2016-11-14 10:31:25 5
2016-11-14 10:31:00 5
我的查询:
SELECT
MIN(dt) Start,
MAX(dt) End,
TIMEDIFF(MAX(dt),MIN(dt)) as sessionTime,
FROM table
WHERE sessionTime > "00:02:00"
GROUP BY session_id
此查询不提供任何结果。
这就是我喜欢的结果:
Start End sessionTime
2016-11-15 11:20:00 2016-11-15 11:25:00 00:05:00
2016-11-15 09:27:00 2016-11-15 09:37:00 00:10:00
2016-11-14 21:31:00 2016-11-14 21:37:00 00:06:00
答案 0 :(得分:0)
SELECT session_id
MIN(dt) Start,
MAX(dt) End,
TIMEDIFF(MAX(dt),MIN(dt)) as sessionTime
FROM table
GROUP BY session_id
Having sessionTime > "00:02:00"