Created
February 21, 2018 16:16
-
-
Save RedaAffane/540d583492856538240e85d034d1287c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT *, | |
CASE WHEN | |
"time_difference" >= INTERVAL '30 days' THEN 1 ELSE 0 END AS "flag_macro_session_limits" | |
FROM( | |
SELECT *, | |
LAG("timestamp",1) OVER ( | |
PARTITION BY "user_id" | |
ORDER BY "timestamp" DESC | |
) | |
- "timestamp" as "time_difference" | |
FROM( | |
SELECT "user_id", | |
"channel", | |
"timestamp" | |
FROM( | |
SELECT "user_id", | |
"channel", | |
"timestamp", | |
SUM("keep_touchpoint") as "keep_touchpoint" | |
FROM "non_converting_macro_sessions" | |
GROUP BY "user_id", "channel", "timestamp" | |
) t1 | |
WHERE "keep_touchpoint" = 0 | |
) t2 | |
) t3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment