user2673664 user2673664 - 16 days ago 6
MySQL Question

Mysql, show results with a Timediff on more then 2 min

I like to only show result with TIMEDIFF on MORE then 2 min

Table:

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


My query:

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


This query do not giv any results.

This is how I like the results:

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

Answer
SELECT session_id

    MIN(dt) Start,
    MAX(dt) End,
    TIMEDIFF(MAX(dt),MIN(dt)) as sessionTime

FROM table
GROUP BY session_id
Having sessiontime...
Comments