Advertisement
YuvalGai

Untitled

Sep 8th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.08 KB | None | 0 0
  1. select
  2. INTERVAL_DATE
  3. ,LTV_GROUP
  4. ,LEAGUE
  5. ,TROPHY_GROUP
  6. ,payers_segment
  7. ,SENIORITY_BIN
  8. ,TRANSACTION_SOURCE
  9. ,RESOURCE_ID
  10. ,COIN_PRICE
  11. ,RESOURCE_CNT
  12. ,OCCASIONS_BOUGHT
  13. ,COINS_SPENT
  14. ,COINS_PER_ITEM
  15. ,INTERVAL_DATE as LAST_UPDATED_DT
  16. ,current_timestamp() as DW_INSERT_DT
  17. from
  18. (
  19. (
  20. (
  21. select
  22. date(derived_tstamp) interval_date,
  23. ltv_group_static ltv_group,
  24. league,
  25. trophy_group,
  26. payers_segment,
  27. seniority_bin,
  28. 'boxes' transaction_source,
  29. to_varchar(prize_container [0] [1]) resource_id,
  30. coin_price,case
  31. when prize_container [0] [1] like '%Big%' then mode(resource_cnt) * 6
  32. when prize_container [0] [1] like '%Small%' then mode(resource_cnt) * 3
  33. end resource_cnt,case
  34. when prize_container [0] [1] like '%Big%' then round(count(*) / 6)
  35. when prize_container [0] [1] like '%Small%' then round(count(*) / 3)
  36. end occasions_bought,case
  37. when prize_container [0] [1] like '%Big%' then round(sum(coin_price) / 6)
  38. when prize_container [0] [1] like '%Small%' then round(sum(coin_price) / 3)
  39. end coins_spent,
  40. sum(coin_price) / count(*) coins_per_item
  41. from
  42. (
  43. select
  44. A.*,
  45. B.ltv_group ltv_group_static,
  46. B.league,
  47. B.trophy_group,
  48. B.payers_segment,
  49. B.seniority_bin
  50. from
  51. (
  52. (
  53. select
  54. *,
  55. date(derived_tstamp) interval_date
  56. from
  57. MATCH_MASTERS.PROD.F_USER_RESOURCE_TRANSACTION
  58. where 1=1
  59. and date(derived_tstamp) >= current_date - 61
  60. and is_coin_paid = 1
  61. and is_received_resource = TRUE
  62. and is_chest = 1
  63. ) A
  64. left join (
  65. select
  66. user_id,
  67. interval_date,
  68. ltv_group,CASE
  69. WHEN trophies_cnt < 3800 THEN 'Studios'
  70. WHEN trophies_cnt < 30000 THEN 'Master_League'
  71. WHEN trophies_cnt >= 30000 THEN 'Legends_League'
  72. END as league,
  73. CASE
  74. WHEN trophies_cnt < 1500 THEN '0-1500'
  75. WHEN trophies_cnt < 3800 THEN '1500-3800'
  76. WHEN trophies_cnt < 8000 THEN '3800-8000'
  77. WHEN trophies_cnt < 17000 THEN '8000-17000'
  78. WHEN trophies_cnt < 30000 THEN '17000-30000'
  79. ELSE '30000+'
  80. END AS trophy_group,
  81. payers_segment,
  82. seniority_bin
  83. from
  84. MATCH_MASTERS.prod.daily_users_from_params
  85. where 1=1
  86. and interval_date >= current_date - 61
  87. ) B on A.user_id = B.user_id
  88. and A.interval_date = B.interval_date
  89. )
  90. )
  91. where
  92. is_chest = 1
  93. and is_coin_paid = 1
  94. and date(derived_tstamp) >= current_date - 61
  95. group by
  96. 1,
  97. 2,
  98. 3,
  99. 4,
  100. 5,
  101. 6,
  102. 7,
  103. 8,
  104. 9
  105. )
  106. union all
  107. (
  108. SELECT
  109. interval_date,
  110. ltv_group_static ltv_group,
  111. league,
  112. trophy_group,
  113. payers_segment,
  114. seniority_bin,
  115. transaction_source,
  116. resource_id,
  117. coin_price,
  118. resource_cnt,
  119. count(*) occasions_bought,
  120. sum(coin_price) coins_spent,
  121. sum(coin_price) / count(*) coins_per_item
  122. from
  123. (
  124. select
  125. A.*,
  126. B.ltv_group ltv_group_static,
  127. B.league,
  128. B.payers_segment,
  129. B.trophy_group,
  130. B.seniority_bin
  131. from
  132. (
  133. (
  134. select
  135. *,
  136. date(derived_tstamp) interval_date
  137. from
  138. MATCH_MASTERS.PROD.F_USER_RESOURCE_TRANSACTION
  139. where
  140. date(derived_tstamp) >= current_date - 61
  141. and is_coin_paid = 1
  142. and is_received_resource = TRUE
  143. and is_chest = 0
  144. and transaction_source != 'daily_deals'
  145. ) A
  146. left join (
  147. select
  148. user_id,
  149. interval_date,
  150. ltv_group,CASE
  151. WHEN trophies_cnt < 3800 THEN 'Studios'
  152. WHEN trophies_cnt < 30000 THEN 'Master_League'
  153. WHEN trophies_cnt >= 30000 THEN 'Legends_League'
  154. END as league,
  155. CASE
  156. WHEN trophies_cnt < 1500 THEN '0-1500'
  157. WHEN trophies_cnt < 3800 THEN '1500-3800'
  158. WHEN trophies_cnt < 8000 THEN '3800-8000'
  159. WHEN trophies_cnt < 17000 THEN '8000-17000'
  160. WHEN trophies_cnt < 30000 THEN '17000-30000'
  161. ELSE '30000+'
  162. END AS trophy_group,
  163. payers_segment,
  164. seniority_bin
  165. from
  166. MATCH_MASTERS.prod.daily_users_from_params
  167. where 1=1
  168. and interval_date >= current_date - 61
  169. ) B on A.user_id = B.user_id
  170. and A.interval_date = B.interval_date
  171. )
  172. )
  173. group by
  174. 1,
  175. 2,
  176. 3,
  177. 4,
  178. 5,
  179. 6,
  180. 7,
  181. 8,
  182. 9,
  183. 10
  184. order by
  185. 1 desc,
  186. 2,
  187. 3
  188. )
  189. union all
  190. (
  191. SELECT
  192. interval_date,
  193. ltv_group_static ltv_group,
  194. league,
  195. trophy_group,
  196. payers_segment,
  197. seniority_bin,
  198. transaction_source,
  199. resource_id,
  200. resource_cnt coin_price,
  201. 1 resource_cnt,
  202. count(*) occasions_bought,
  203. sum(resource_cnt) coins_spent,
  204. resource_cnt coins_per_item
  205. from
  206. (
  207. select
  208. A.*,
  209. B.ltv_group ltv_group_static,
  210. B.league,
  211. B.payers_segment,
  212. B.trophy_group,
  213. B.seniority_bin
  214. from
  215. (
  216. (
  217. select
  218. *,
  219. date(derived_tstamp) interval_date
  220. from
  221. MATCH_MASTERS.PROD.F_USER_RESOURCE_TRANSACTION
  222. where 1=1
  223. and date(derived_tstamp) >= current_date - 61
  224. and resource_id = 'Coin'
  225. and is_received_resource = FALSE
  226. and transaction_source in ('tournament', 'match_end', 'create_team')
  227. ) A
  228. left join (
  229. select
  230. user_id,
  231. interval_date,
  232. ltv_group,CASE
  233. WHEN trophies_cnt < 3800 THEN 'Studios'
  234. WHEN trophies_cnt < 30000 THEN 'Master_League'
  235. WHEN trophies_cnt >= 30000 THEN 'Legends_League'
  236. END as league,
  237. CASE
  238. WHEN trophies_cnt < 1500 THEN '0-1500'
  239. WHEN trophies_cnt < 3800 THEN '1500-3800'
  240. WHEN trophies_cnt < 8000 THEN '3800-8000'
  241. WHEN trophies_cnt < 17000 THEN '8000-17000'
  242. WHEN trophies_cnt < 30000 THEN '17000-30000'
  243. ELSE '30000+'
  244. END AS trophy_group,
  245. payers_segment,
  246. seniority_bin
  247. from
  248. MATCH_MASTERS.prod.daily_users_from_params
  249. where
  250. interval_date >= current_date - 61
  251. ) B on A.user_id = B.user_id
  252. and A.interval_date = B.interval_date
  253. )
  254. )
  255. group by
  256. 1,
  257. 2,
  258. 3,
  259. 4,
  260. 5,
  261. 6,
  262. 7,
  263. 8,
  264. 9,
  265. 10
  266. order by
  267. 1 desc,
  268. 2,
  269. 3
  270. )
  271. )
  272. union all
  273. (
  274. SELECT
  275. interval_date,
  276. ltv_group_static ltv_group,
  277. league,
  278. trophy_group,
  279. payers_segment,
  280. seniority_bin,
  281. transaction_source,
  282. offer_id resource_id,
  283. coin_price,
  284. 1 resource_cnt,
  285. count(*) occasions_bought,
  286. sum(coin_price) coins_spent,
  287. sum(coin_price) / count(*) coins_per_item
  288. from
  289. (
  290. select
  291. A.*,
  292. B.ltv_group ltv_group_static,
  293. B.league,
  294. B.payers_segment,
  295. B.trophy_group,
  296. B.seniority_bin
  297. from
  298. (
  299. (
  300. select
  301. *,
  302. date(derived_tstamp) interval_date
  303. from
  304. MATCH_MASTERS.PROD.F_USER_RESOURCE_TRANSACTION
  305. where 1=1
  306. and date(derived_tstamp) >= current_date - 61
  307. and resource_id = 'Coin'
  308. and is_received_resource = FALSE
  309. and transaction_source = 'daily_deals'
  310. ) A
  311. left join (
  312. select
  313. user_id,
  314. interval_date,
  315. ltv_group,CASE
  316. WHEN trophies_cnt < 3800 THEN 'Studios'
  317. WHEN trophies_cnt < 30000 THEN 'Master_League'
  318. WHEN trophies_cnt >= 30000 THEN 'Legends_League'
  319. END as league,
  320. CASE
  321. WHEN trophies_cnt < 1500 THEN '0-1500'
  322. WHEN trophies_cnt < 3800 THEN '1500-3800'
  323. WHEN trophies_cnt < 8000 THEN '3800-8000'
  324. WHEN trophies_cnt < 17000 THEN '8000-17000'
  325. WHEN trophies_cnt < 30000 THEN '17000-30000'
  326. ELSE '30000+'
  327. END AS trophy_group,
  328. payers_segment,
  329. seniority_bin
  330. from
  331. MATCH_MASTERS.prod.daily_users_from_params
  332. where 1=1
  333. and interval_date >= current_date - 61
  334. ) B on A.user_id = B.user_id
  335. and A.interval_date = B.interval_date
  336. )
  337. )
  338. group by
  339. 1,
  340. 2,
  341. 3,
  342. 4,
  343. 5,
  344. 6,
  345. 7,
  346. 8,
  347. 9,
  348. 10
  349. order by
  350. 1 desc,
  351. 2,
  352. 3
  353. )
  354. )
  355. where 1=1
  356. and interval_date >= current_date - 61
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement