SELECT DISTINCT
a.id AS account_id,
o.id AS charge_operation_id,
ot.code AS operation_type_code,
o.ops_assignee_decision_id AS direct_decision_id,
pr.id AS register_row_id,
pr.ops_assignee_decision_id AS register_decision_id,
d.number AS decision_number
FROM back_office.account a
JOIN back_office.transaction t
ON t.credit_account_id = a.id
JOIN back_office.operation o
ON o.id = t.operation_id
LEFT JOIN back_office.operation_type ot
ON ot.id = o.operation_type_id
LEFT JOIN back_office.ops_payment_register_decision pr
ON pr.charge_operation_id = o.id
LEFT JOIN back_office.ops_assignee_decision d
ON d.id = coalesce(
o.ops_assignee_decision_id,
pr.ops_assignee_decision_id
)
WHERE a.id IN (
40479607,
40756491,
41462141,
41462398,
41462623
)
AND o.approved IS NOT NULL
AND o.deleted IS NULL
ORDER BY a.id, o.id, pr.id;