SELECT
o.id AS operation_id,
ot.code AS operation_type_code,
o.effective_date,
o.ops_payment_register_id AS register_id,
sum(t.value) AS debited_value
FROM back_office.transaction t
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
WHERE t.debit_account_id = 41628689
AND o.approved IS NOT NULL
AND o.deleted IS NULL
GROUP BY
o.id,
ot.code,
o.effective_date,
o.ops_payment_register_id
ORDER BY o.effective_date DESC, o.id DESC
LIMIT 10;