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