SHARE
TWEET

Untitled

a guest Oct 21st, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2.     customer_recent_spend_categories.name, COUNT(*)
  3. FROM
  4.     customers
  5.         LEFT JOIN
  6.     customer_recent_spend_categories ON customer_recent_spend_categories.id = (SELECT
  7.             id
  8.         FROM
  9.             customer_recent_spend_categories
  10.         WHERE
  11.             value < (SELECT
  12.                     SUM(sell_total) / 1.2
  13.                 FROM
  14.                     orders
  15.                 WHERE
  16.                     customers.id = customer_id
  17.                         AND inserted = 1
  18.                         AND orders.created_at >= (NOW() - INTERVAL 90 DAY)
  19.                         AND orders.deleted_at IS NULL
  20.                 GROUP BY customer_id)
  21.                 AND customer_recent_spend_categories.deleted_at IS NULL
  22.         ORDER BY value DESC
  23.         LIMIT 1)
  24. WHERE
  25.     customer_recent_spend_categories.name IN ('A' , 'B', 'C', 'D', 'E', 'F', 'G')
  26. GROUP BY customer_recent_spend_categories.name
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top