SELECT m.registration_id, m.Fee_type, m.Amount - g.Paid as Owing FROM fee_details_memo m
JOIN (SELECT p.registration_id, p.Fee_type, SUM(p.Amount) as Paid FROM fee_paid_details p
GROUP BY p.registration_id, p.Fee_type) AS g
ON m.registration_id= g.registration_id AND m.Fee_type = g.Fee_type