SQLite的。如何计算聚合列的总和

时间:2015-02-27 11:50:38

标签: sqlite aggregate-functions

例如,我有这样的查询:

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

如何计算我的列?

0 个答案:

没有答案