Advertisement
YuvalGai

Untitled

Sep 8th, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.86 KB | None | 0 0
  1. SELECT
  2. match_end_date,
  3. league,
  4. match_type,
  5. pvp_mode,
  6. trophies_percentile,
  7. elo_percentile,
  8. is_rival_bot,
  9. resource_sub_type,
  10. rival_resource_sub_type,
  11. booster_name,
  12. match_end_date as LAST_UPDATED_DT,
  13. current_timestamp() as DW_INSERT_DT,
  14. mode(min_trophies_in_trophies_percentile) min_trophies_in_trophies_percentile,
  15. mode(max_trophies_in_trophies_percentile) max_trophies_in_trophies_percentile,
  16. round(mode(avg_trophies_in_trophies_percentile)) avg_trophies_in_trophies_percentile,
  17. mode(median_trophies_in_trophies_percentile) median_trophies_in_trophies_percentile,
  18. mode(unique_users_in_trophies_percentile) unique_users_in_trophies_percentile,
  19. round(mode(avg_trophy_gap)) avg_trophy_gap_in_match_type_per_trophy_percentile_group,
  20.  
  21. mode(min_elo_in_elo_percentile) min_elo_in_elo_percentile,
  22. mode(max_elo_in_elo_percentile) max_elo_in_elo_percentile,
  23. round(mode(avg_elo_in_elo_percentile)) avg_elo_in_elo_percentile,
  24. mode(median_elo_in_elo_percentile) median_elo_in_elo_percentile,
  25. mode(unique_users_in_elo_percentile) unique_users_in_elo_percentile,
  26. round(mode(avg_elo_gap)) avg_elop_in_match_type_per_elo_percentile_group,
  27.  
  28. SUM(is_won) wins,
  29. COUNT(*) matches,
  30. SUM(
  31. CASE
  32. WHEN rival_resource_sub_type = 'Special Edition'
  33. OR rival_resource_sub_type = 'Legendary' THEN 1
  34. END
  35. ) matches_agianst_LESE,
  36. SUM(match_duration_sec) match_duration_sec
  37. FROM
  38. (
  39. SELECT
  40. *,
  41. avg(trophy_gap) OVER (partition BY match_end_date, league, match_type, trophies_percentile) avg_trophy_gap,
  42. MIN(trophies_cnt) OVER(partition BY match_end_date, league, trophies_percentile) min_trophies_in_trophies_percentile,
  43. MAX(trophies_cnt) OVER(partition BY match_end_date, league, trophies_percentile) max_trophies_in_trophies_percentile,
  44. median(trophies_cnt) OVER(partition BY match_end_date, league, trophies_percentile) median_trophies_in_trophies_percentile,
  45. avg(trophies_cnt) OVER(partition BY match_end_date, league, trophies_percentile) avg_trophies_in_trophies_percentile,
  46. COUNT(DISTINCT user_id) OVER(partition BY match_end_date, league, trophies_percentile) unique_users_in_trophies_percentile,
  47.  
  48. avg(elo_gap) OVER (partition BY match_end_date, league, match_type, elo_percentile) avg_elo_gap,
  49. MIN(previous_elo_balance) OVER(partition BY match_end_date, league, elo_percentile) min_elo_in_elo_percentile,
  50. MAX(previous_elo_balance) OVER(partition BY match_end_date, league, elo_percentile) max_elo_in_elo_percentile,
  51. median(previous_elo_balance) OVER(partition BY match_end_date, league, elo_percentile) median_elo_in_elo_percentile,
  52. avg(previous_elo_balance) OVER(partition BY match_end_date, league, elo_percentile) avg_elo_in_elo_percentile,
  53. COUNT(DISTINCT user_id) OVER(partition BY match_end_date, league, elo_percentile) unique_users_in_elo_percentile
  54.  
  55. FROM
  56. (
  57. SELECT
  58. A.*,
  59. B.trophies_percentile,
  60. B.elo_percentile,
  61. abs(trophies_cnt - rival_trophies_balance) trophy_gap,
  62. abs(previous_elo_balance - previous_rival_elo_balance) elo_gap
  63. FROM
  64. (
  65. SELECT
  66. match_end_date,
  67. user_id,
  68. pvp_mode,
  69. match_type,
  70. is_rival_bot,
  71. is_won,
  72. rival_trophies_balance,
  73. trophies_cnt,
  74. resource_sub_type,
  75. rival_resource_sub_type,
  76. booster_name,
  77. match_duration_sec,
  78. previous_elo_balance,
  79. rival_elo-(elo-previous_elo_balance) previous_rival_elo_balance,
  80. case
  81. when previous_trophies_balance < 3800 then 'Studios'
  82. when previous_trophies_balance < 30000 then 'MR'
  83. when previous_trophies_balance >= 30000 then 'LL'
  84. else 'Check data'
  85. End league
  86. FROM
  87. MATCH_MASTERS.prod.f_user_match
  88. WHERE 1=1
  89. AND match_end_date >= current_date - 91
  90. AND pvp_mode in ('PvP','Showdown')
  91. AND (is_private IS NULL OR is_private = FALSE)
  92. and is_rival_bot = 0
  93. ) A
  94.  
  95. LEFT JOIN (
  96. SELECT
  97. user_id
  98. , interval_date
  99. , trophies_percentile
  100. , elo_percentile
  101. FROM MATCH_MASTERS.PROD.DAILY_USERS_FROM_PARAMS
  102. WHERE
  103. is_active = 1
  104. and interval_date >= current_date - 91
  105. ) B ON A.user_id = B.user_id
  106. AND A.match_end_date = B.interval_date
  107. )
  108. )
  109. where 1=1
  110. and MATCH_END_DATE >= current_date - 91
  111.  
  112. GROUP BY ALL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement