我有以下查询;你可以帮我吗?我有comboAmount和TotalPrice,我想将TotalPrice + Combo Amount添加到newComboAmount中,但它显示错误的结果,因为我的ComboUniqueId与其他不同请查看下面的图片和查询
SELECT
CAST(CASE
WHEN a.TotalPrice != 0
THEN 1
ELSE 0
END AS bit) AS CheckOtherPrice,
a.OrderDetailId, a.ItemId,
b.ItemCode, b.ItemName,
e.GroupName,
a.Quantity, a.Price, a.TotalPrice,
a.OrderId, ISNULL(a.ComboId, 0) ComboId,
(a.ComboAmount + SUM(a.TotalPrice) OVER (ORDER BY a.OrderDetailId)) AS new_comboamount,
a.ComboGroupId, a.ComboAmount, a.ComboUniqueId,
c.ComboName, d.GroupName ComboGroupName,
a.OfferMasterId
FROM
OrderDetail a
INNER JOIN
ItemMaster b ON a.ItemId = b.ItemId AND a.OrderId IN (985)
INNER JOIN
ItemGroup e ON b.ItemGroupId = e.ItemGroupId
LEFT JOIN
ComboMaster c ON a.ComboId = c.ComboId
LEFT JOIN
ComboGroup d ON a.ComboGroupId = d.GroupId
答案 0 :(得分:2)
我认为你只需要一个partition by
:
( a.ComboAmount + sum(a.TotalPrice) over (partition by combouniqueid order by a.OrderDetailId) ) as new_comboamount