Skip to content

Instantly share code, notes, and snippets.

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"
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 *,
def subsets(s):
'''
This function returns all the possible subsets of a set of channels.
input :
- s: a set of channels.
'''
if len(s)==1:
return s
else:
sub_channels=[]