Skip to content

3497. Analyze Subscription Conversion 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
WITH
  FreeTrial AS (
    SELECT user_id, AVG(activity_duration) AS avg_free_trial_duration
    FROM UserActivity
    WHERE activity_type = 'free_trial'
    GROUP BY 1
  ),
  Paid AS (
    SELECT user_id, AVG(activity_duration) AS avg_paid_duration
    FROM UserActivity
    WHERE activity_type = 'paid'
    GROUP BY 1
  ),
  ConvertedUsers AS (
    SELECT DISTINCT FreeTrial.user_id
    FROM FreeTrial
    INNER JOIN Paid
      USING (user_id)
  )
SELECT
  ConvertedUsers.user_id,
  ROUND(FreeTrial.avg_free_trial_duration, 2) AS trial_avg_duration,
  ROUND(Paid.avg_paid_duration, 2) AS paid_avg_duration
FROM ConvertedUsers
INNER JOIN FreeTrial
  USING (user_id)
INNER JOIN Paid
  USING (user_id)
ORDER BY 1;