更新时间:2019-11-05 来源:黑马程序员 浏览量:
现有两个表如下:borrow_log表中borrower与debtor字段记录着users表的id,写一条SQL统计出每个借钱方欠每个男性债主的款项汇总(gender:1-男,2-女)。
参考答案:
select borrow_log.borrower,sum(amount) from users left join borrow_log on users.id = borrow_log.debtor where users.gender = 1 group by borrow_log.borrower,borrow_log.debtor
本文来自:黑马程序员软件测试学院 test.itheima.com