Skip to content
Advertisement

Gap-and-island for more than time threshold

I have these tables:

I want to investigate sessions of a user having time time difference between successive rows greater than 5 minutes, reporting:

  • session and session mode
  • number of sessions with the gap-and-island problem.

My attempt:

Error:

Expected results:

Note: dbfiddle.

Advertisement

Answer

The problem is we have two user_id and they’re not defined so you need to specifically choose them and give them aliases.

session_id timestamp user_id start_time number_of_sessions_with_problem
656 2016-04-01 00:16:19.687 9 2016-04-01 00:03:39 2
657 2016-04-01 00:26:51.096 9 2016-04-01 00:26:51 2

Fiddle

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement