Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.71 KB | None | 0 0
  1. SELECT tq.enquiry_id as 'TQ ID',
  2. tq.affiliate_id as 'Affiliate ID',
  3. (case status_id
  4. when 0 then 'pending'
  5. when 1 then 'approved'
  6. when 2 then 'declined' end) as 'TQ Status',
  7. (case type_id
  8. when 1 then 'declined'
  9. when 2 then 'incorrect'
  10. when 3 then 'untracked' end) as 'Enquiry Type',
  11. tq.amount, tq.commission,
  12. CONVERT_TZ(tq.date_sale, 'GMT', 'Europe/London') AS 'TQ Date',
  13.  CONVERT_TZ(tq.date_sale, 'GMT', 'Europe/London') AS 'Transaction Date',
  14. tq.order_ref as 'Order Ref',
  15. (SELECT REPLACE(REPLACE(tq.description,CHAR(13), ' '), CHAR(10), ' ')) AS 'Description',
  16. tq.duplicate_transaction_id,
  17. at.extra as 'Original Order Ref',
  18. at.affiliate_id as 'Original Affiliate',
  19.  CONVERT_TZ(at.date, 'GMT', 'Europe/London') AS 'Original Tansaction Date',
  20.  (CASE at.commission_status
  21.         WHEN - 1 THEN 'Deleted'
  22.         WHEN 1 THEN 'Confirmed'
  23.         WHEN 2 THEN 'Declined'
  24.         ELSE 'Pending'
  25.     END) AS 'Original Status',
  26. at.sale_amount as 'Original Sale Amount',
  27. at.commission as 'Original Commission',
  28. IFNULL(GROUP_CONCAT(CONCAT(cg.code, ':', tp.sale_amount) SEPARATOR '|'), 'N/A') AS 'parts',
  29. at.com_date as 'Valiation Date'
  30.  
  31.  FROM transaction_query.transaction tq
  32. left join  affiliatewindow.transaction  at on at.id=duplicate_transaction_id and at.merchant_id=4329
  33. LEFT JOIN affiliatewindow.transaction_part tp ON tp.transaction_id = at.id
  34.  LEFT JOIN affiliatewindow.commission_group cg ON cg.id = tp.cg_id
  35. where tq.merchant_id = 4329
  36. and tq.status_id=0
  37. AND tq.date_sale BETWEEN CONVERT_TZ(DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 DAY), '%Y-%m-%d 00:00:00'), 'Europe/London', 'GMT') AND CONVERT_TZ(DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 DAY), '%Y-%m-%d 23:59:59'), 'Europe/London', 'GMT')
  38. group by tq.enquiry_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement