Tables:
cust table:    
   cust_id, name, etc    
bill table:    
   bill_id, cust_id, amt, due_date, status (open/closed)
payment table:    
   payment_id, bill_id, amt etc
Customer can settle a single bill by paying multiple installments. So, one bill_id may relate to payment_ids.
I am unable to generate this recordset:
cust_id | due amt
'due amt' is the sum of all bill.amts - sum of all payment.amts and having status open.
Bill table
bill_id cust_id     amt     status
1       18          200     open
2       18          200     open
3       17          200     open
4       17          200     open
5       17          200     open
6       17          200     closed
Payment table
payment_id  bill_id cust_id amt
1           1       18      50
2           2       18      40
3           3       17      10
Expected output
cust_id     due_amt         hint/how
17          590             (600-10) .. 600 -> because one is closed
18          310             (400-(50+40))
 
    