我需要按订单ID计算不同产品的总销售额。 我的桌子就像。
Product Order_ID Sales
AAA Dress 100
AAA Dress 50
AAA Pen 150
BBB Dress 80
BBB Paint 50
CCC Chocolate 100
CCC Chocolate 10
CCC Chocolate 30
答案 0 :(得分:1)
这对你有用..
SELECT Product, Order_Id, SUM(Sales) AS 'TotalSales'
FROM Table GROUP BY Product, Order_Id ORDER BY Order_Id, Product
答案 1 :(得分:0)
SELECT *,
SUM(Sales) OVER(PARTITION BY Product, Order_ID) AS Total_Sales
FROM Your_Table