miholeus

yandex payments

May 30th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.79 KB | None | 0 0
  1. SELECT
  2.     b.`id`,
  3.     b.type,
  4.     SUM(IF(pt_inc.amount,pt_inc.amount, 0)) - SUM(IF(pt_out.amount,pt_out.amount, 0)) AS trans_total,
  5.     (
  6.         (b.`doc_sum` + b.`doc_commision`)
  7.     ) AS doc_total,
  8.     b.`doc_sum`,
  9.     b.doc_comment,
  10.     b.`doc_commision`
  11. FROM
  12.     `payment_to_bank_x_operation` AS o
  13. JOIN `payment_to_bank` AS b ON o.`pay_id` = b.`id`
  14. LEFT JOIN `payment_transactions` AS pt_inc ON o.`transaction_id` = pt_inc.`id`
  15. AND pt_inc. STATUS != 'deleted'
  16. AND pt_inc.type = 'income'
  17. LEFT JOIN `payment_transactions` AS pt_out ON o.`transaction_id` = pt_out.`id`
  18. AND pt_out. STATUS != 'deleted'
  19. AND pt_out.type = 'outcome'
  20. where b.type = 5 and b.id IN (SELECT id FROM payment_to_bank where type = 5 and status = 1)
  21. GROUP BY
  22.     o.`pay_id`
  23. HAVING
  24.     abs(trans_total) != abs(doc_total)
Advertisement
Add Comment
Please, Sign In to add comment