我试图获得计算列的总和并显示为单独的不同行(ItemCode),但没有成功。我爱上我靠近的解决方案,但不知何故,我再次SQL查询SUM列的乘积列的总和
坚持我的查询:
select
I.Itemcode,
Cast((POL.Receivedqty) as Int) as QTY,
Cast(SUM(POL.Receivedqty * POL.RW_CostPrice) as Money) as TotalVolumexBuyPrice,
Cast(SUM(POL.ReceivedQty * POL.ItemPrice) as Money) as TotalVolumexCPROSellPrice,
Cast(POL.RW_CostPrice as Money) as LatestCostPrice,
Cast(POL.ItemPrice as money) as LatestSellPrice,
Convert(Varchar, max(POL.Completedate), 111) as LastOrderDate
From
initem as I
left join
InpurchaseOrderLine as POL on I.ItemID = POL.ItemID
where
POL.CompleteDate between '2014-10-01' and '2015-10-01'
and I.Itemcode not like '1000015697'
and I.Itemcode like '1000001453' or I.Itemcode like '1000019133'
Group by
I.ItemCode, POL.ItemPrice, POL.RW_CostPrice, POL.Receivedqty
Order by
POL.RW_CostPrice
这将返回这样的数据:的
ItemCode QTY Cost x QTY Sell x QTY CostPrice SellPrice
1000001453 0 0.00 0.00 794.00 941.37
1000001453 14 11116.00 13179.18 794.00 941.37
1000001453 15 11910.00 14120.55 794.00 941.37
1000001453 20 31760.00 37654.80 794.00 941.37
1000001453 14 25592.00 26358.36 914.00 941.37
1000001453 20 73120.00 75309.60 914.00 941.37
1000001453 30 27420.00 28241.10 914.00 941.37
1000001453 31 28334.00 29182.47 914.00 941.37
1000019133 1 39781.90 45232.02 3978.19 4523.202
1000019133 2 7956.38 9046.404 3978.19 4523.202
1000019133 1 3978.19 4523.2022 3978.19 4523.2022
1000019133 0 0.00 0.00 3978.19 4523.21
1000019133 1 43760.09 49755.31 3978.19 4523.21
1000019133 2 7956.38 9046.4 3978.19 4523.21
1000019133 2 7956.38 9408.2658 3978.19 4704.1329
1000019133 2 8274.64 9408.2658 4137.32 4704.1329
但我想获得类似的东西(总和款项):
ItemCode QTY Cost x QTY Sell x QTY
1000001453 238 209252.00 224046.06
1000001933 11 119661.00 136418.00
感谢Brino,做了这份工作。 – Brunoxp