Advertisement
clickio

Script to disable user's site areas withoud statistics

Feb 11th, 2022
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.85 KB | None | 0 0
  1. DROP TEMPORARY TABLE IF EXISTS adunits_to_disable;
  2. CREATE TEMPORARY TABLE adunits_to_disable
  3. SELECT DISTINCT sa.site_area_id, bsa.user_id, sa.`create_date`, bsa.adv_expense_gbp_30, bsa.requests_30 FROM rabota_db.site_area sa
  4. JOIN bi.site_area bsa ON bsa.site_area_id = sa.site_area_id
  5. LEFT JOIN rabota_db.attached_site_areas basa ON sa.site_area_id  = basa.site_area_id # with attached site area
  6. LEFT JOIN bi.site_area asai ON asai.site_area_id = basa.attached_site_area_id # attached site areas info
  7. WHERE
  8.     (
  9.     (
  10.         basa.site_area_id IS NOT NULL # is base area
  11.     AND ((asai.adv_expense_gbp_30 = 0 #and have no attached areas with stats
  12.     AND asai.requests_30 = 0 )
  13.     OR asai.site_area_id IS NULL) # or have no attached areas
  14.    
  15.     )
  16.     OR
  17.     (
  18.         basa.site_area_id IS NULL # is attached area itself
  19.     )
  20.     )
  21. AND bsa.adv_expense_gbp_30 = 0
  22. AND bsa.requests_30 = 0
  23. AND sa.`create_date` < ( NOW() - INTERVAL 3 MONTH )
  24. AND bsa.user_id IN (
  25. 143718,
  26. 130905,
  27. 142171,
  28. 143779,
  29. 143174,
  30. 111441,
  31. 145613,
  32. 145397,
  33. 143885,
  34. 103491,
  35. 119997,
  36. 142788,
  37. 144892,
  38. 145417,
  39. 128837,
  40. 116214,
  41. 145592,
  42. 141408,
  43. 143924,
  44. 114289,
  45. 125676,
  46. 143727,
  47. 128317,
  48. 117170,
  49. 130221,
  50. 127672,
  51. 113821,
  52. 122065,
  53. 145832,
  54. 118982,
  55. 132210,
  56. 130273,
  57. 136691,
  58. 122345,
  59. 140542,
  60. 129927,
  61. 108350,
  62. 128603,
  63. 142114,
  64. 142210,
  65. 146294,
  66. 125922,
  67. 143448,
  68. 114096,
  69. 146466,
  70. 123677,
  71. 124567,
  72. 127942,
  73. 130955,
  74. 134435,
  75. 143263,
  76. 144357,
  77. 111604,
  78. 140209,
  79. 102556,
  80. 129416,
  81. 131176,
  82. 141405,
  83. 141406,
  84. 145591,
  85. 108589,
  86. 141407,
  87. 117333,
  88. 122213,
  89. 123741,
  90. 126356,
  91. 140846,
  92. 143637,
  93. 143764,
  94. 144135,
  95. 146308,
  96. 116989,
  97. 109931,
  98. 111040,
  99. 118339,
  100. 120761,
  101. 126239,
  102. 131337,
  103. 132502,
  104. 134210,
  105. 141900,
  106. 143139,
  107. 108973,
  108. 113159,
  109. 142135
  110. );
  111.  
  112. UPDATE site_area sa
  113. JOIN adunits_to_disable dsa ON sa.`site_area_id` = dsa.`site_area_id`
  114. SET sa.active = 0,
  115. sa.modify_date = NOW() #,
  116. #sa.deleted = 1
  117. ;
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement