Skip to content

Instantly share code, notes, and snippets.

@malisper
Last active June 19, 2017 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malisper/4d56f24726733b390d07d45b3d9c6883 to your computer and use it in GitHub Desktop.
Save malisper/4d56f24726733b390d07d45b3d9c6883 to your computer and use it in GitHub Desktop.
SELECT
SUM(funnel_events(
ARRAY_AGG(funnel_step ORDER BY time ASC, funnel_step DESC),
2)) AS funnel_results
FROM ((SELECT *
FROM (SELECT user_id,
time,
0 AS funnel_step
FROM "events"
WHERE type = 'click'
AND text = 'Login'
AND time BETWEEN 1476428400000 AND 1477033200000) events_1)
UNION ALL
(SELECT *
FROM (SELECT user_id,
time,
1 AS funnel_step
FROM "events"
WHERE type = 'click'
AND text = 'Purchase'
AND time BETWEEN 1476428400000 AND 1477033200000) events_2)
) events_query
GROUP BY user_id;
@Zaksh
Copy link

Zaksh commented Jun 19, 2017

shoudn't the line 11 (AND text = 'Login') be AND text = 'SignUp', as the example is demonstrating

customer wants to know what percentage of the users who have signed up in a given week later made a purchase that same week [1]

How come Login is same as singed up ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment