Advertisement
YuvalGai

Untitled

Mar 5th, 2023
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 7.19 KB | None | 0 0
  1. CREATE OR REPLACE TABLE CANDIVORE.SEMANTIC_LAYER.T_MATCHMAKING_DASHBOARD AS
  2.  
  3.  
  4. SELECT match_end_date, league, match_type,percentile,resource_sub_type,booster_name,mode(min_trophies_in_percentile) min_trophies_in_percentile, mode(max_trophies_in_percentile) max_trophies_in_percentile,round(mode(avg_trophies_in_percentile)) avg_trophies_in_percentile, mode(median_trophies_in_percentile) median_trophies_in_percentile,mode(unique_users_in_percentile) unique_users_in_percentile, round(mode(avg_trophy_gap)) avg_trophy_gap_in_match_type_per_percentile_group, SUM(is_won) wins, COUNT(*) matches, SUM(CASE WHEN rival_resource_sub_type = 'Special Edition' OR rival_resource_sub_type = 'Legendary' THEN 1 ELSE 0 END) matches_agianst_LESE FROM (
  5. SELECT *
  6. , avg(trophy_gap) OVER (partition BY match_end_date, league, match_type ,percentile) avg_trophy_gap
  7. , MIN(trophies_cnt) OVER(partition BY match_end_date, league, percentile) min_trophies_in_percentile
  8. , MAX(trophies_cnt) OVER(partition BY match_end_date, league, percentile) max_trophies_in_percentile
  9. , median(trophies_cnt) OVER(partition BY match_end_date, league, percentile) median_trophies_in_percentile
  10. , avg(trophies_cnt) OVER(partition BY match_end_date, league, percentile) avg_trophies_in_percentile
  11. , COUNT(DISTINCT user_id) OVER(partition BY match_end_date, league, percentile) unique_users_in_percentile
  12. FROM (
  13.  
  14.  
  15. SELECT * FROM
  16. (SELECT A.*,B.LEAGUE,B.trophies_cnt,true_trophies_cnt,percentile, abs(true_trophies_cnt-rival_trophies_balance) trophy_gap FROM
  17.  
  18.  
  19. (SELECT match_end_date, user_id, match_id,match_type,is_won,rival_trophies_balance, trophies_cnt true_trophies_cnt,CASE
  20. WHEN booster_name = 'FoxyRoxySE' THEN 'Special Edition'
  21. WHEN booster_name = 'MonkeyJoojoo' THEN 'Legendary'
  22. WHEN booster_name = 'BroccoBoogie' THEN 'Legendary'
  23. WHEN booster_name = 'CleoCadabra' THEN 'Legendary'
  24. WHEN booster_name ='BillieBoom' THEN 'Legendary'
  25. WHEN booster_name ='CupidSE' THEN 'Special Edition'
  26. WHEN booster_name ='DoctorColorSE' THEN 'Special Edition'
  27. WHEN booster_name ='ElMagnetoSE' THEN 'Special Edition'
  28. WHEN booster_name ='AllAboardSE' THEN 'Special Edition'
  29. WHEN booster_name ='CupidSE' THEN 'Special Edition'
  30. WHEN booster_name ='AllAboard' THEN 'Diamond 2'
  31. WHEN booster_name ='AutoMatcher' THEN 'Gold'
  32. WHEN booster_name ='BalloonBlast' THEN 'Gold'
  33. WHEN booster_name ='BlazingBoard' THEN 'Gold'
  34. WHEN booster_name ='ColonelMcQuack' THEN 'Diamond 1'
  35. WHEN booster_name ='CrazyClovers' THEN 'Diamond 1'
  36. WHEN booster_name ='CrossAttack' THEN 'Gold'
  37. WHEN booster_name ='Painter' THEN 'Silver'
  38. WHEN booster_name ='UFOBeamSE' THEN 'Special Edition'
  39. WHEN booster_name ='Cupid' THEN 'Diamond 3'
  40. WHEN booster_name ='DoctorColor' THEN 'Diamond 3'
  41. WHEN booster_name ='ElMagneto' THEN 'Diamond 3'
  42. WHEN booster_name ='FoxyRoxy' THEN 'Diamond 2'
  43. WHEN booster_name ='JeevesBot' THEN 'Diamond 2'
  44. WHEN booster_name ='Lightsabers' THEN 'Diamond 1'
  45. WHEN booster_name ='Magic' THEN 'Gold'
  46. WHEN booster_name ='MrAppleberry' THEN 'Diamond 1'
  47. WHEN booster_name ='QueenCobra' THEN 'Diamond 2'
  48. WHEN booster_name ='SpecialDelivery' THEN 'Silver'
  49. WHEN booster_name ='SweepIt' THEN 'Gold'
  50. WHEN booster_name ='UFOBeam' THEN 'Diamond 2'
  51. WHEN booster_name ='WoollyWorkout' THEN 'Diamond 3'
  52. WHEN booster_name ='Infection' THEN 'Silver'
  53. WHEN booster_name ='RubberDucky' THEN 'Bronze'
  54. WHEN booster_name ='SmallBoom' THEN 'Bronze'
  55. WHEN booster_name ='CreateSpecials' THEN 'Silver'
  56. ELSE 'bugged?'
  57. END resource_sub_type,CASE
  58. WHEN rival_booster_name = 'FoxyRoxySE' THEN 'Special Edition'
  59. WHEN rival_booster_name = 'MonkeyJoojoo' THEN 'Legendary'
  60. WHEN rival_booster_name = 'BroccoBoogie' THEN 'Legendary'
  61. WHEN rival_booster_name = 'CleoCadabra' THEN 'Legendary'
  62. WHEN rival_booster_name ='BillieBoom' THEN 'Legendary'
  63. WHEN rival_booster_name ='CupidSE' THEN 'Special Edition'
  64. WHEN rival_booster_name ='DoctorColorSE' THEN 'Special Edition'
  65. WHEN rival_booster_name ='ElMagnetoSE' THEN 'Special Edition'
  66. WHEN rival_booster_name ='AllAboardSE' THEN 'Special Edition'
  67. WHEN rival_booster_name ='CupidSE' THEN 'Special Edition'
  68. WHEN rival_booster_name ='AllAboard' THEN 'Diamond 2'
  69. WHEN rival_booster_name ='AutoMatcher' THEN 'Gold'
  70. WHEN rival_booster_name ='BalloonBlast' THEN 'Gold'
  71. WHEN rival_booster_name ='BlazingBoard' THEN 'Gold'
  72. WHEN rival_booster_name ='ColonelMcQuack' THEN 'Diamond 1'
  73. WHEN rival_booster_name ='CrazyClovers' THEN 'Diamond 1'
  74. WHEN rival_booster_name ='CrossAttack' THEN 'Gold'
  75. WHEN rival_booster_name ='Painter' THEN 'Silver'
  76. WHEN rival_booster_name ='UFOBeamSE' THEN 'Special Edition'
  77. WHEN rival_booster_name ='Cupid' THEN 'Diamond 3'
  78. WHEN rival_booster_name ='DoctorColor' THEN 'Diamond 3'
  79. WHEN rival_booster_name ='ElMagneto' THEN 'Diamond 3'
  80. WHEN rival_booster_name ='FoxyRoxy' THEN 'Diamond 2'
  81. WHEN rival_booster_name ='JeevesBot' THEN 'Diamond 2'
  82. WHEN rival_booster_name ='Lightsabers' THEN 'Diamond 1'
  83. WHEN rival_booster_name ='Magic' THEN 'Gold'
  84. WHEN rival_booster_name ='MrAppleberry' THEN 'Diamond 1'
  85. WHEN rival_booster_name ='QueenCobra' THEN 'Diamond 2'
  86. WHEN rival_booster_name ='SpecialDelivery' THEN 'Silver'
  87. WHEN rival_booster_name ='SweepIt' THEN 'Gold'
  88. WHEN rival_booster_name ='UFOBeam' THEN 'Diamond 2'
  89. WHEN rival_booster_name ='WoollyWorkout' THEN 'Diamond 3'
  90. WHEN rival_booster_name ='Infection' THEN 'Silver'
  91. WHEN rival_booster_name ='RubberDucky' THEN 'Bronze'
  92. WHEN rival_booster_name ='SmallBoom' THEN 'Bronze'
  93. WHEN rival_booster_name ='CreateSpecials' THEN 'Silver'
  94. ELSE 'bugged?'
  95. END rival_resource_sub_type, booster_name FROM candivore.prod.f_user_match WHERE match_end_date > '2022-10-12' AND pvp_mode = 'PvP' AND match_type != 'Challenge') A
  96.  
  97. LEFT JOIN
  98.  
  99. (SELECT *, CASE
  100. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.1 THEN 'p0-p10'
  101. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.2 THEN 'p10-p20'
  102. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.3 THEN 'p20-p30'
  103. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.4 THEN 'p30-p40'
  104. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.5 THEN 'p40-p50'
  105. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.6 THEN 'p50-p60'
  106. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.7 THEN 'p60-p70'
  107. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.8 THEN 'p70-p80'
  108. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.9 THEN 'p80-p90'
  109. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.95 THEN 'p90-p95'
  110. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 0.99 THEN 'p95-p99'
  111. WHEN rrn/total_daily_matches_in_arena_group_and_match_type <= 1 THEN 'p99-p100' END percentile
  112. FROM
  113. (
  114. SELECT *,MAX(rrn) OVER (partition BY interval_date, league) total_daily_matches_in_arena_group_and_match_type
  115. FROM
  116. (
  117. (SELECT interval_date,user_id,trophies_cnt,CASE
  118.     WHEN login_arena<=13 THEN 'Studios'
  119.     WHEN login_arena<=22 THEN 'Master_League'
  120.     WHEN login_arena>=23 THEN 'Legends_League' END league
  121. ,ROW_NUMBER() OVER(partition BY interval_date, league ORDER BY trophies_cnt) rrn
  122. FROM CANDIVORE.PROD.DAILY_USERS_FROM_PARAMS WHERE is_active = 1 AND interval_date > '2022-09-12')
  123. )
  124. )
  125. ) B
  126.  
  127. ON A.user_id = B.user_id AND A.match_end_date = B.interval_date)
  128. )
  129.  
  130.  
  131. ) GROUP BY 1,2,3,4,5,6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement