This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Explain Order_stats

By: a guest on Nov 14th, 2012  |  syntax: MySQL  |  size: 1.21 KB  |  views: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data