更新時間:2019-11-05 來源:黑馬程序員 瀏覽量:
現(xiàn)有兩個表如下:borrow_log表中borrower與debtor字段記錄著users表的id,寫一條SQL統(tǒng)計出每個借錢方欠每個男性債主的款項匯總(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
本文來自:黑馬程序員軟件測試學(xué)院 test.itheima.com