I am tring to perform a calculation in my query. I've been working on it for hours, so I need another pair of eyes to see what I am missing. Everything in the query is working except for the g.courseFee part. The course fee is not being added to the calculation. I am not sure if the issue is in the select clause or the left join clause. Below is my query and any help is greatly appreciated:
SELECT COALESCE(SUM(c.amount),0)+COALESCE(SUM(g.courseFee),0) AS 'Balance',
a.termCode as 'Term',
a.stuID AS 'Student ID',
CONCAT(d.lname, ', ', d.fname) AS 'Student Name',
a.comment AS Comment
FROM bill a
LEFT JOIN student_fee b on a.stuID = b.stuID AND a.ID = b.billID
LEFT JOIN billing_table c ON b.feeID = c.ID
LEFT JOIN person d ON a.stuID = d.personID
LEFT JOIN payment e on a.stuID = e.stuID and a.termCode = e.termCode
LEFT JOIN stu_course_sec f ON a.stuID = f.stuID AND e.termCode = f.termCode
LEFT JOIN course_sec g ON f.termCode = g.termCode AND f.courseSecCode = g.courseSecCode
GROUP BY a.stuID,a.termCode