我想返回一堆列并添加其中一列。
表:
订单ID
OrderNum
金额
我希望返回OrderID,金额以及每个orderID金额的总和。像这样的东西(OrderID - OrderNum - Amount - Total):
答案 0 :(得分:0)
select t1.orderid, t1.amount, t2.sum_amount
from your_table t1
join
(
select orderid, sum(amount) as sum_amount
from your_table
group by orderid
) t2 on t1.orderid = t2.orderid
答案 1 :(得分:0)
在Oracle中,您可以使用窗口函数:
SELECT
OrderID,
OrderNum,
Amount ,
SUM(Amount) OVER (PARTITION BY OrderID) as Total
FROM OrderLine