Skip to content

Instantly share code, notes, and snippets.

@RedaAffane
Last active February 21, 2018 11:50
Show Gist options
  • Save RedaAffane/7859e05a1191b559d7ca43fe08faad3c to your computer and use it in GitHub Desktop.
Save RedaAffane/7859e05a1191b559d7ca43fe08faad3c to your computer and use it in GitHub Desktop.
SELECT
*,
CASE WHEN
EXTRACT(epoch FROM "timestamp")
- LAG(
EXTRACT(epoch FROM "timestamp")
) OVER (
PARTITION BY "user_id"
ORDER BY "timestamp"
) >= 30 * 60 THEN 1 ELSE 0 END as new_micro_session
FROM log_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment