比如查询所有贷款客户的已还金额总和、未还金额总和,可以这样做:
select sum(case when status='paid' then corpus else null end),sum(case when status='unpaid' then corpus else null end) from Loan group by userId;
比如查询所有贷款客户的已还金额总和、未还金额总和,可以这样做:
select sum(case when status='paid' then corpus else null end),sum(case when status='unpaid' then corpus else null end) from Loan group by userId;