Last active
February 22, 2018 08:29
-
-
Save RedaAffane/2c9c7924d2fd75a2de969d304f2f98e9 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 "user_id", | |
| "user_id" || SUM("flag_macro_session_limits") OVER ( | |
| PARTITION BY "user_id" | |
| ORDER BY "timestamp" ASC | |
| ) | |
| - "flag_macro_session_limits" AS "user_macro_session", | |
| "channel", | |
| "timestamp" | |
| FROM( | |
| 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 | |
| ) t4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment