Postgres: Sum from multiple joins resulting in values being more than expected
Join against the results of the aggregation:

select inv.*
from invoices inv
  left join (
    select invoice_id, COALESCE(SUM(amount + discount), 0) as total_payments
    from invoice_payments
    group by invoice_id
  ) ip on ip.invoice_id = inv.id
  left join (
    select invoice_id, coalesce(sum(amount),0) as total_credit
    from invoice_credit_notes
    group by invoice_id
  ) icn on icn.invoice_id = inv.id
where coalesce(ip.total_payments,0) + coalesce(icn.total_credit,0) &lt; ROUND(inv.grand_total, 0))