Skip to content

Instantly share code, notes, and snippets.

@RedaAffane
Last active February 21, 2018 16:02
Show Gist options
  • Save RedaAffane/d5386e9d22c36c3b97f2f2a3897dc123 to your computer and use it in GitHub Desktop.
Save RedaAffane/d5386e9d22c36c3b97f2f2a3897dc123 to your computer and use it in GitHub Desktop.
SELECT *,
CASE WHEN
"timestamp" >= "conversion_timestamp" - interval '30 days'
AND "timestamp" <= "conversion_timestamp"
THEN 1 else 0 END as "keep_touchpoint"
FROM(
SELECT "conversions".user_id,
"conversions".conversion_timestamp,
"touchpoints".channel,
"touchpoints".timestamp,
"conversions".user_id || extract(epoch from "conversions"."conversion_timestamp") AS "macro_user_session"
FROM "conversions" "conversions"
LEFT JOIN "user_touchpoints" "touchpoints"
ON "conversions"."user_id" = "touchpoints"."user_id"
) t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment