Advertisement
vuylov

Untitled

Mar 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.17 KB | None | 0 0
  1. SELECT
  2.     sad.stat_term,
  3.     SUM(sad.stat_enters) as enters,
  4.     SUM(sad.stat_hits) as hits,
  5.     ROUND(SUM(`stat_enters`*`src_coef`)) as `clicks`,
  6.     ROUND(SUM(`stat_teas`) / SUM(sad.stat_enters) * 100, 2) as percent_clicks,
  7.     SUM(`stat_teas`) as `teaser_views`,
  8.     SUM(`stat_teased`) as `teaser_clicks`,
  9.     ROUND(SUM(`stat_teas`) / SUM(`stat_teased`), 2) as teaser_per,
  10.     ROUND(SUM(sc.`src_per`* sad.`stat_enters`)) as costs,
  11.     ROUND(SUM(`stat_enters`*`src_per`) / (SUM(`stat_orders_all`) - SUM(`stat_orders_trash`))) as cost_per_order,
  12.     SUM(sad.stat_orders_profit) as profit
  13. FROM `stat_A_days` as sad
  14. LEFT JOIN stat_cost as sc ON sc.src_date = sad.stat_date AND sc.src_name = sad.stat_source
  15. WHERE sad.`stat_date` >= '2017-12-01' AND sad.stat_source = 'marketgid'
  16. GROUP BY sad.`stat_term`
  17. HAVING
  18.     (SUM(sad.stat_enters) >= 200 AND ROUND(SUM(`stat_teas`) / SUM(sad.stat_enters) * 100, 2) <= 10)
  19.     OR
  20.     (SUM(sad.stat_enters) >= 50 AND IFNULL(ROUND(SUM(`stat_teas`) / SUM(`stat_teased`), 2), 1.2) <= 1.2)
  21.     OR
  22.     (SUM(sad.stat_enters) > 3000 AND IFNULL(ROUND(SUM(`stat_enters`*`src_per`) / (SUM(`stat_orders_all`) - SUM(`stat_orders_trash`)), 2), 800) >= 800)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement