SHARE
TWEET

Untitled

a guest Apr 19th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH sum_orders AS (
  2.     SELECT SUM(link_orders) as link_orders
  3.     FROM  stat_links
  4.     WHERE link_date >= NOW() - INTERVAL 3 DAY
  5. )
  6. SELECT SUM(t.part) as zero
  7. FROM (
  8.        SELECT /*s.link_id, SUM(s.link_profit) as profit, SUM(s.link_orders) as orders,
  9.               IF(SUM(s.link_orders) = 0, 0, ROUND(SUM(s.link_profit) / SUM(s.link_orders), 2)) as profitPerOrder,
  10.               o.link_orders,
  11.               IFNULL(pl.period_link_orders, 0),
  12.               IFNULL(pl.period_link_orders / o.link_orders, 0) as coef,*/
  13.               IF(SUM(s.link_orders) = 0, 0, ROUND(SUM(s.link_profit) / SUM(s.link_orders), 2)) * IFNULL(pl.period_link_orders / o.link_orders, 0) as part
  14.        FROM stat_links as s
  15.               LEFT JOIN (
  16.          SELECT l.link_id, SUM(l.link_orders) as period_link_orders
  17.          FROM stat_links as l
  18.          WHERE link_date >= NOW() - INTERVAL 3 DAY
  19.          GROUP BY l.link_id
  20.        ) as pl ON pl.link_id = s.link_id
  21.               LEFT JOIN  sum_orders as o ON 1 = 1
  22.        WHERE s.link_date > NOW() - INTERVAL 14 DAY
  23.        GROUP BY s.link_id
  24.        ) as t
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top