Advertisement
OKyJIucT

Untitled

Jun 1st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. SELECT
  2.  
  3. deals.id as deal_id,
  4. payments.id as payment_id,
  5. deals.type,
  6. products.name as product,
  7. CONCAT_WS(',', countries.`name`) as 'GEO',
  8. teams.name as 'department',
  9. DATE(payments.created_at),
  10. payments.usd_summary,
  11. CONCAT_WS(',', affiliate_sites.`name`) as 'ad_url',
  12. NULL as 'ad_places',
  13. NULL as 'results',
  14. wallet_types.name as payment_method,
  15. 'test',
  16. '5 - Реклама' as 'cost_item',
  17. payments.comment as 'about',
  18. CONCAT_WS(',', affiliate_sites.`foreign_id`) as 'site_ids',
  19. 'CRM' as 'source',
  20. payment_targets.name as payment_target
  21.  
  22. FROM payments
  23.  
  24. LEFT JOIN deals ON deals.id = payments.deal_id
  25. LEFT JOIN deal_places ON deals.id = deal_places.deal_id
  26. LEFT JOIN departments ON deals.department_id = departments.id
  27. LEFT JOIN partners ON partners.id = deals.partner_id
  28. LEFT JOIN products ON products.id = partners.product_id
  29. LEFT JOIN team_users ON team_users.user_id = deals.manager_id
  30. LEFT JOIN teams ON teams.id = team_users.team_id
  31. LEFT JOIN countries ON deal_places.country_id = countries.id
  32. LEFT JOIN affiliate_sites ON affiliate_sites.id = deal_places.site_id
  33. LEFT JOIN wallets ON wallets.id = payments.wallet_id
  34. LEFT JOIN wallet_types ON wallet_types.id = wallets.wallet_type_id
  35. LEFT JOIN payment_targets ON payment_targets.id = payments.payment_target_id
  36.  
  37. WHERE payments.created_at BETWEEN '2020-03-01 00:00:00.000000' AND '2020-03-31 23:59:59.000000' AND payments.status = 'done' AND deals.type != 'google_docs' AND deals.type != 'zid_cid' GROUP BY payments.id
  38.  
  39. UNION
  40.  
  41. SELECT
  42.  
  43. deals.id as deal_id,
  44. payments.id as payment_id,
  45. deals.type,
  46. products.name as product,
  47. CONCAT_WS(',', countries.`name`) as 'GEO',
  48. teams.name as 'department',
  49. DATE(payments.created_at),
  50. payments.usd_summary,
  51. CONCAT_WS(',', deal_buying_stats.`link`) as 'ad_url',
  52. NULL as 'ad_places',
  53. NULL as 'results',
  54. wallet_types.name as payment_method,
  55. 'test',
  56. '5 - Реклама' as 'cost_item',
  57. payments.comment as 'about',
  58. CONCAT_WS(',', affiliate_sites.`foreign_id`) as 'site_ids',
  59. 'CRM' as 'source',
  60. payment_targets.name as payment_target
  61.  
  62. FROM payments
  63.  
  64. LEFT JOIN deals ON deals.id = payments.deal_id
  65. LEFT JOIN deal_places ON deals.id = deal_places.deal_id
  66. LEFT JOIN departments ON deals.department_id = departments.id
  67. LEFT JOIN partners ON partners.id = deals.partner_id
  68. LEFT JOIN products ON products.id = partners.product_id
  69. LEFT JOIN team_users ON team_users.user_id = deals.manager_id
  70. LEFT JOIN teams ON teams.id = team_users.team_id
  71. LEFT JOIN countries ON deal_places.country_id = countries.id
  72. LEFT JOIN zid ON zid.deal_id = deals.id
  73. LEFT JOIN affiliate_sites ON affiliate_sites.id = zid.site_id
  74. LEFT JOIN wallets ON wallets.id = payments.wallet_id
  75. LEFT JOIN wallet_types ON wallet_types.id = wallets.wallet_type_id
  76. LEFT JOIN payment_targets ON payment_targets.id = payments.payment_target_id
  77. LEFT JOIN deal_buying_stats ON deal_buying_stats.deal_id = payments.deal_id
  78.  
  79. WHERE payments.created_at BETWEEN '2020-03-01 00:00:00.000000' AND '2020-03-31 23:59:59.000000' AND payments.status = 'done' AND deals.type = 'zid_cid' GROUP BY payments.id
  80.  
  81. UNION
  82.  
  83. SELECT
  84.  
  85. deals.id as deal_id,
  86. payments.id as payment_id,
  87. deals.type,
  88. products.name as product,
  89. deals_tmp.geo,
  90. teams.name as 'department',
  91. DATE(payments.created_at),
  92. payments.usd_summary,
  93. deals_tmp.ad_url,
  94. deals_tmp.ad_places,
  95. deals_tmp.results,
  96. deals_tmp.wallet_type as payment_method,
  97. deals_tmp.extention,
  98. deals_tmp.cost_item,
  99. deals_tmp.about,
  100. CONCAT_WS(',', deal_places.`site_id`) as 'site_ids',
  101. 'GOOGLE DOCS' as 'source',
  102. payment_targets.name as payment_target
  103.  
  104. FROM payments
  105.  
  106. LEFT JOIN deals ON deals.id = payments.deal_id
  107. LEFT JOIN deals_tmp ON deals.id = deals_tmp.deal_id
  108. LEFT JOIN deal_places ON deals.id = deal_places.deal_id
  109. LEFT JOIN team_users ON team_users.user_id = deals.manager_id
  110. LEFT JOIN teams ON teams.id = team_users.team_id
  111. LEFT JOIN partners ON partners.id = deals.partner_id
  112. LEFT JOIN products ON products.id = partners.product_id
  113. LEFT JOIN payment_targets ON payment_targets.id = payments.payment_target_id
  114.  
  115. WHERE payments.created_at BETWEEN '2020-03-01 00:00:00.000000' AND '2020-03-31 23:59:59.000000' AND payments.status = 'done' AND deals.type = 'google_docs' GROUP BY payments.id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement