如何计算SQL Server Northwind数据库中每个EmployeeId
折扣后产品的总金额?
Northwind数据库使用的表是:
答案 0 :(得分:0)
如果您正在计算每个EmployeeId的金额 你必须再使用一个表来连接这些表
,您的查询应为
select O.EmployeeID,OD.ProductID,Sum(OD.UnitPrice*Quantity *(1-Discount)) as TotalAmount from Orders as o
inner join [Order Details] as OD on OD.OrderID=o.OrderID
inner join Products as p on p.ProductID=OD.ProductID
group by OD.ProductID,o.EmployeeID
order by OD.ProductID