一共有3個表,
goods表,有3個字段: id (int,PK) , price (float), name (varchar(20))
buyer表,有2個字段: id(int,PK) ,name (varchar(20))
buyRecord表,有3個字段:id(int PK), buyerId(int,FK) , goodsId(int,FK)
問題:
如何用一句或多句語句查詢出buyer表中id為0的用戶的消費總金額?
select sum(good.price) from good inner join buyRecord on (good.id = buyRecord.goodsId) where buyRecord.buyerId = 0;