SQL 聚合函数或 GROUP BY 问题!
发布网友
发布时间:2022-04-10 00:39
我来回答
共1个回答
热心网友
时间:2022-04-10 02:09
既然Shopper 和 ShopOrder 一对一关系
那么可以直接在group by后面加上sr.name
select sr.Name, sum(gs.Price * od.Amount) as 'Total Rate' /*gs.Price 货物价格, od.Amount 订购的数量*/
from ShopOrder as so
join OrderDetail as od
on od.ShopOrderID = so.ID
join Goods as gs
on od.GoodsID = gs.ID
join Shopper as sr
on sr.ID = so.ShopperID
group by sr.ID, sr. Name