I want to select data from mysql. And also wanted to do some calculation at query excution time. I had two sql tables:
Loan Table :
loan_id|Customer_name|Total_amount
1000 |Sashika |55000
1001 |Amell |11000
Settlement Table :
Sett_id|Loan_id|Amount
a123 |1000 |1000
b123 |1001 |2000
Thats how my two tables look like. I want to get due value of loans. I used below code to generate but it wont' show correct values.
select loan.loan_id,loan.customer_name,loan.total_amount,sum(settlement.amount) as 'Total Received',
((loan.total_amount)-sum(settlement.amount ))as 'Total Due'
from loan , settlement
where loan.loan_id = 1001;
This code get value of total(column) of settelement table. When I try with another loan id(where loan_id=) also amount of total of settlement value show and calculate. But It isn't the value I want. Please help me guys
Loan_ID| Customer_Name|Total_Amount|Total_Received|Total_Due
1000 |Sashika |55000 |1000 |54000
This is How I want Thanks for edit my question and make it more understandable :)