我想从另一个表中获取每个订单的销售总额以及客户和员工详细信息
订单明细表
OrderID ProductID UnitPrice Quantity Discount
10248 11 10 1 0
10248 42 20 2 0
10248 72 20 3 0
10249 14 10 1 0
10249 51 40 2 0
订单表
OrderID CustomerName EmployeeName
10248 C1 E1
10249 C2 E2
所需结果
orderid sales Customer Employee
10248 110 C1 E1
10249 90 C2 E2
所以我需要每个订单的总销售额(例如10248订单的销售额为10 * 1 + 20 * 2 + 20 * 3 = 10 + 40 + 60 = 110)以及相应的员工姓名和客户姓名
查询已尝试
select od.orderid, Unitprice * Quantity as sales
group by od.orderid
From [Order Details] od
inner join orders o on od.orderid = o.orderid
错误:
关键字“从”附近的语法不正确。
FROM
belongs beforeGROUP BY
.加入订单信息:
您需要按订单进行汇总,然后取每个订单的销售总额:
Try the following, you are having a
group by
beforefrom
. Also you do not need to dogroup by
if you are using no aggregation instead you can usedistinct.