SELECT 
    r.id, 
    r.amountPaid, 
    cr.amount AS amountUnpaid, 
    r.payed, 
    r.companyFk
FROM receipt r
    JOIN client c ON c.id = r.clientFk
    JOIN bi.customer_risk cr ON cr.customer_id = c.id
        AND cr.company_id = r.companyFk
WHERE r.id = ?