1

我有两张表 Loan 和 Member。现在在贷款中我有列总金额,在成员中我有列作为成员类型,在贷款中我有根据成员类型的各种贷款。现在我想使用 SUM 函数根据 memtype 计算 totalamount。

我尝试了以下方法:

select sum(totalamount) from loan,member where member.mem_type='Regular'
4

1 回答 1

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
于 2012-04-07T11:44:54.197 回答