0

所以基本上我有下面的查询。我正在尝试将第二列和第三列以及第四列相加。我按shiptoaddrressno 和shiptoname 分组。是否可以使用原始的数量和扩展价格值计算出第四列中的等式?计算已关闭,因为我正在对列求和以使查询工作。

declare @rundate datetime
set @rundate = '3/11/2013'


Declare @Sales table (ShipToAddressNo int, ShipToName varchar(40), SumOfQuantityShipped int, 
                        SumOfAmountShipped money, TotalDeductions float)
INSERT INTO @Sales
SELECT
    ShipToAddressNo,
    ShipToName,
    sum(QuantityShipped),
    sum(ExtendedPrice),
    (p.[Transfer Price] * QuantityShipped) +
    (p.[Profit Split Calculation 1 (Prasco Distribution Allowance)] * QuantityShipped) +
    (p.[Profit Split Calculation 2 (Share to Partner)] * QuantityShipped) +
    (p.[Profit Split Calculation 3 (Cost Adjustment)] * QuantityShipped) +
    (p.[Profit Split Calculation  (Cost Adjustment)] * QuantityShipped) +
    (p.[Net Sales Profit Split] * QuantityShipped) TotalDeductions --Sum this entire line 
FROM
    SalesSummary ss join [Product] p 
        on ss.ShortItemNo = p.SDITM
    join JDE_PRODUCTION.PRODDTA.F4101 im 
        on im.IMITM = p.SDITM
WHERE 
    InvoiceDate = @RunDate
GROUP BY
    ShipToAddressNo,
    ShipToName
4

1 回答 1

0

这是你想要的吗?

sum((p.[Transfer Price] * QuantityShipped) +
    (p.[Profit Split Calculation 1 (Prasco Distribution Allowance)] * QuantityShipped) +
    (p.[Profit Split Calculation 2 (Share to Partner)] * QuantityShipped) +
    (p.[Profit Split Calculation 3 (Cost Adjustment)] * QuantityShipped) +
    (p.[Profit Split Calculation  (Cost Adjustment)] * QuantityShipped) +
    (p.[Net Sales Profit Split] * QuantityShipped)
   ) as TotalDeductions --Sum this entire line 
于 2013-09-10T13:09:09.383 回答