例如,我有这样的查询:
select
pc.[Sum] as PlanSum,
case when Sum(TransferOut.[Sum]) is null then 0 else Sum(TransferOut.[Sum]) end as TOut,
case when Sum(TransferIn.[Sum]) is null then 0 else Sum(TransferIn.[Sum]) end as TIn
from PlannedCost pc
left join Transfer TransferOut on pc.id = TransferOut.PlanCostFromId
left join Transfer TransferIn on pc.id = TransferOut.PlanCostToId
如果我更改我的查询以计算这样的列:
pc.[Sum] as PlanSum,
case when Sum(TransferOut.[Sum]) is null then 0 else Sum(TransferOut.[Sum]) end as TOut,
case when Sum(TransferIn.[Sum]) is null then 0 else Sum(TransferIn.[Sum]) end as TIn,
(pc.[Sum] - TOut + TIn) as CountedPlanSum,
我收到了一个错误:
没有这样的专栏:TOut
如何计算我的列?