mysql for select using sum in another table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charles07
    New Member
    • Dec 2011
    • 45

    mysql for select using sum in another table

    guys, please help

    i need balance amount of fees all students has to pay. Following is the DB structure. `feepayid` is primary key for paymentstable and paymentregister & `studentid` is primary in studentstable. I have written a query for this, please evaluate the query.

    please see the attachment for the db structure


    Code:
    SELECT d.`studentid`, SUM(a.`totalfee` - (SELECT SUM(`feeamount`) FROM `paymentstable`  WHERE a.`feepayid` = `feepayid`)) AS balancefee
    FROM `studentstable` d
    LEFT JOIN `paymentregister` a ON a.`studentid` = d.`studentid`
    GROUP BY d.`studentid`;
    Attached Files
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Explain the business rules a bit more. Which table contains the amounts that students are supposed to pay and which one contains the amounts that students actually paid?

    Comment

    Working...