Advertisement
kirzecy670

Untitled

Aug 29th, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH ax AS (
  2. select
  3.     uid
  4. from
  5.     stat.funnelTrack
  6. where
  7.     dt >= today() - INTERVAL '14' DAY
  8.     and action in ('open_parent_activity', 'open')
  9.     AND ((deviceType = 1
  10.         AND appVersion % 2 = 1)
  11.     OR (deviceType = 2
  12.         AND appVersion % 2 = 0))
  13. GROUP BY
  14.     uid),
  15. payments AS (
  16. SELECT
  17.     uid,
  18.     MAX(IF(concat(Type, Value) IN ('subscription_30', 'subscription_365'), 1, 0)) AS SubscriptionPurchase,
  19.     MAX(IF(Sku LIKE '%care_plus%' OR Sku LIKE '%premium%' OR Product Like '%care%', 1, 0)) AS PlusSubscriptionPurchase
  20. FROM
  21.     analytics.money
  22. WHERE
  23.     ChargeNumber >= 1
  24.     AND NOT was_refunded
  25.     AND USDNet >= 0.02
  26.     AND ContractCharge_TM >= today() - INTERVAL '13' MONTH
  27. GROUP BY
  28.     uid
  29. )
  30. SELECT
  31. SubscriptionPurchase,
  32. PlusSubscriptionPurchase,
  33.     count(*) AS users
  34. --  uniqCombined(uid) AS uniq,
  35. --  SUM(SubscriptionPurchase) SubscriptionPurchase,
  36. --  SUM(PlusSubscriptionPurchase) PlusSubscriptionPurchase
  37. FROM ax t1 LEFT JOIN payments t2 using(uid)
  38. GROUP BY 1, 2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement