Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- b.`id`,
- b.type,
- SUM(IF(pt_inc.amount,pt_inc.amount, 0)) - SUM(IF(pt_out.amount,pt_out.amount, 0)) AS trans_total,
- (
- (b.`doc_sum` + b.`doc_commision`)
- ) AS doc_total,
- b.`doc_sum`,
- b.doc_comment,
- b.`doc_commision`
- FROM
- `payment_to_bank_x_operation` AS o
- JOIN `payment_to_bank` AS b ON o.`pay_id` = b.`id`
- LEFT JOIN `payment_transactions` AS pt_inc ON o.`transaction_id` = pt_inc.`id`
- AND pt_inc. STATUS != 'deleted'
- AND pt_inc.type = 'income'
- LEFT JOIN `payment_transactions` AS pt_out ON o.`transaction_id` = pt_out.`id`
- AND pt_out. STATUS != 'deleted'
- AND pt_out.type = 'outcome'
- where b.type = 5 and b.id IN (SELECT id FROM payment_to_bank where type = 5 and status = 1)
- GROUP BY
- o.`pay_id`
- HAVING
- abs(trans_total) != abs(doc_total)
Advertisement
Add Comment
Please, Sign In to add comment