我有两张桌子贷款和会员。现在在贷款我有列totalamount和在成员我有列作为membertype和在贷款我有各种贷款根据membertype。现在我想使用SUM函数根据memtype计算totalamount。
我尝试了以下内容:
select sum(totalamount) from loan,member where member.mem_type='Regular'
答案 0 :(得分:1)
你的意思是这样的:
select sum(totalamount) AS Total
from loan
JOIN member ON Memberid=loan.Memberid
where member.mem_type='Regular'
或者,如果你想选择mem_type
,那么就像这样:
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