Advertisement
YuvalGai

Untitled

Jul 25th, 2023
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. SELECT interval_date_2, max_30d_max_daily_price_point_grouped, count(distinct user_id) unique_users from
  2. (
  3. SELECT interval_date_2, user_id, max(max_30d_max_daily_price_point_grouped) max_30d_max_daily_price_point_grouped from
  4. (
  5. SELECT B.user_id, B.interval_date, B.interval_date_2 ,B.country, B.LANGUAGE , B.platform , B.app_version , B.app_minor_version , B.install_date , B.trophy_group, B.league, B.ltv_group, B.ltv_group_30d, C.max_30d_max_daily_price_point,C.max_20d_max_daily_price_point, row_number() OVER(PARTITION BY B.USER_ID, interval_date_2 ORDER BY B.INTERVAL_DATE DESC) RN
  6. , CASE
  7. WHEN C.max_30d_max_daily_price_point <= 3.5 then '0-3.5'
  8. WHEN C.max_30d_max_daily_price_point <= 5.5 then '3.5-5.5'
  9. WHEN C.max_30d_max_daily_price_point <= 9 then '5.5-9'
  10. WHEN C.max_30d_max_daily_price_point <= 13 then '9-13'
  11. WHEN C.max_30d_max_daily_price_point <= 18 then '13-18'
  12. WHEN C.max_30d_max_daily_price_point <= 28 then '18-28'
  13. WHEN C.max_30d_max_daily_price_point > 28 then '28+'
  14. end max_30d_max_daily_price_point_grouped
  15. FROM
  16. (SELECT
  17. user_id
  18. , interval_date
  19. , case
  20. when interval_date = '2023-06-13' or interval_date = '2023-06-12' then '2023-06-13'
  21. when interval_date = '2023-05-31' or interval_date = '2023-05-30' then '2023-05-31'
  22. else interval_date
  23. end interval_date_2
  24. , country
  25. , LANGUAGE
  26. , platform
  27. , app_version
  28. , app_minor_version
  29. , ltv_group
  30. , DATE(first_install_dt) AS install_date
  31. , CASE
  32. WHEN trophies_cnt < 125 THEN '0-125'
  33. WHEN trophies_cnt < 1400 THEN '125-1400'
  34. WHEN trophies_cnt < 2000 THEN '1400-2000'
  35. WHEN trophies_cnt < 3800 THEN '2000-3800'
  36. WHEN trophies_cnt < 7000 THEN '3800-7000'
  37. WHEN trophies_cnt < 16000 THEN '7000-16000'
  38. WHEN trophies_cnt < 30000 THEN '16000-30000'
  39. WHEN trophies_cnt >= 30000 THEN '30000+'
  40. END AS trophy_group
  41. ,CASE
  42. WHEN trophies_cnt < 800 THEN '800'
  43. WHEN trophies_cnt<3800 THEN 'Studios'
  44. WHEN trophies_cnt<30000 THEN 'Master_League'
  45. WHEN trophies_cnt>=30000 THEN 'Legends_League'
  46. END league
  47. ,case
  48. when iap_30d = 0 then '0'
  49. when iap_30d <= 1 then 'Low (0-1)'
  50. when iap_30d <= 2 then 'Med (1-3)'
  51. when iap_30d <= 5 then 'High (3-8)'
  52. when iap_30d <= 15 then 'Very High (8-15)'
  53. when iap_30d > 15 then 'VIP (15+)'
  54. end ltv_group_30d
  55. FROM candivore.prod.daily_users_from_params WHERE interval_date >= '2022-10-01' and is_active = 1) B
  56.  
  57. left join
  58.  
  59. (select
  60. interval_date
  61. , user_id
  62. , max_daily_price_point
  63. , max(max_daily_price_point) over(partition by user_id order by interval_date
  64. rows BETWEEN 30 PRECEDING AND CURRENT ROW) max_30d_max_daily_price_point
  65. , max(max_daily_price_point) over(partition by user_id order by interval_date
  66. rows BETWEEN 20 PRECEDING AND CURRENT ROW) max_20d_max_daily_price_point
  67. from (select A.interval_date, A.user_id, B.max_daily_price_point from
  68. (select * from
  69. (select distinct user_id from CANDIVORE.PROD.F_IN_APP_PURCHASE
  70. WHERE date(derived_tstamp) >= '2022-10-01') B
  71. full outer join
  72. (select distinct date(derived_tstamp) interval_date from CANDIVORE.PROD.F_IN_APP_PURCHASE WHERE interval_date >= '2022-10-01') A) A
  73. left join
  74. (select
  75. date(derived_tstamp) interval_date
  76. , user_id
  77. , max(price_point) max_daily_price_point
  78. from CANDIVORE.PROD.F_IN_APP_PURCHASE
  79. WHERE interval_date >= '2022-10-01' and purchase_subtype != 'FeelingLucky' and purchase_type != 'Subscription' group by 1,2) B
  80. on A.interval_date = B.interval_date and A.user_id = B.user_id)
  81. WHERE interval_date >= '2022-10-01' group by 1,2,3) C
  82.  
  83. on B.interval_date = C.interval_date and B.user_id = C.user_id
  84. where B.interval_date >= '2022-12-01' and (B.interval_date = '2023-05-31' or B.interval_date = '2023-05-30' or B.interval_date = '2023-05-15' or
  85. B.interval_date = '2023-05-14' or
  86. B.interval_date = '2023-05-01' or
  87. B.interval_date = '2023-04-30' or
  88. B.interval_date = '2023-04-15' or
  89. B.interval_date = '2023-04-14' or
  90. B.interval_date = '2023-06-13' or
  91. B.interval_date = '2023-06-12') and C.max_30d_max_daily_price_point is not null
  92. )
  93. where max_20d_max_daily_price_point is not null
  94. group by 1,2
  95. )
  96. group by 1,2
  97. order by 1 desc, 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement