Reputation: 59
I have two tables Loan and Member. Now in Loan i have column totalamount and in Member i have column as membertype and in Loan i have various loan according to membertype. Now I want to use a SUM function to calculate totalamount according to the memtype.
I tried something as follows :
select sum(totalamount) from loan,member where member.mem_type='Regular'
Upvotes: 1
Views: 1000
Reputation: 31239
Do you mean like this:
select sum(totalamount) AS Total
from loan
JOIN member ON Memberid=loan.Memberid
where member.mem_type='Regular'
Or if you want to select mem_type
as well then something like this:
select sum(totalamount) AS Total,member.mem_type
from loan
JOIN member ON Memberid=loan.Memberid
where member.mem_type='Regular'
GROUP BY member.mem_type
Upvotes: 1