SHARE
TWEET

Explain Order_stats

a guest Nov 14th, 2012 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. EXPLAIN SELECT o2.master_ticket_id, th2.ticket_id,
  2.  IF(get_ticket_count_by_order (o2.master_ticket_id) = 0, COUNT(DISTINCT th2.ticket_id),
  3.     COUNT(DISTINCT IF(
  4.      EXISTS(
  5.       SELECT * FROM merchant_package_characs mpc
  6.       WHERE mpc.merchant_id = th2.merchant_id AND mpc.package_id = th2.package_id AND mpc.name = 'package_type'
  7.         AND mpc.value = 'Merchandise'), NULL, th2.ticket_id) ) ) AS package_tickets,
  8.  IF( get_ticket_count_by_order (o2.master_ticket_id) = 0, COUNT(DISTINCT th2.ticket_id) , get_ticket_count_by_order (th2.master_ticket_id) ) AS order_tickets,
  9.  o2.merchant_id AS merchant, m.name AS merchant_name, package_class,
  10.  customer_type_name AS rate_type, package_desc
  11.  FROM
  12.  ticket_order_header o2
  13.  INNER JOIN ticket_header th2 ON o2.master_ticket_id = th2.master_ticket_id
  14.  INNER JOIN package_header ON th2.package_id = package_header.package_id
  15.  INNER JOIN customer_type ON th2.customer_type = customer_type.customer_type
  16.  INNER JOIN merchant m ON o2.merchant_id = m.merchant_id
  17. WHERE (o2.merchant_id IN (6234) or m.parent_econsignment_merchant_id IN (0) )
  18.  AND order_date >= '2012-01-01'
  19.  AND order_date < DATE_ADD('2012-10-31', INTERVAL 1 DAY)
  20. GROUP BY o2.master_ticket_id, th2.ticket_id
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