列的SQL SELECT SUM返回不正确的值

时间:2018-01-10 07:18:58

标签: sql sql-server

我正在使用SQL select,而部分查询位于

之下
var nodes:[SKNode] = SKNodes();
nodes.append(SKNode());
nodes[0].position = CGPoint(x: 100, y: 100) //should work

它返回4列

    SELECT coalesce(C2.PRE,0) as PRE,coalesce(C4.PREX,0) as PREX,
            coalesce(C2.AFTER,0) as AFTER,  coalesce(C4.AFTERX,0) as AFTERX

我尝试在SQL SELECT中添加3个列,这3列是根据上面的列找到一些SUM值

    1   0   0   0

并返回结果

    PRESUM =(PRE+PREX) = 1+0=1
    AFTERSUM =(AFTER+AFTERX) =0+0=0
    TOTAL =PRESUM+AFTERSUM)= 1+0=1

The new SQL is  

    SELECT coalesce(C2.PRE,0) as PRE, coalesce(C4.PREX,0) as PREX,
          coalesce(C2.AFTER,0) as AFTER,  coalesce(C4.AFTERX,0) as AFTERX,  
           coalesce((PRE+PREX),0) as PRESUM
           coalesce((AFTER+AFTERX),0) as AFTERSUM
           coalesce((PRESUM+AFTERSUM),0) as TOTAL

但是最后3列[PRESUM,AFTERSUM,TOTAL]应该返回1 0 0.我计算总和的方式有什么不对

1 个答案:

答案 0 :(得分:3)

进行算术运算时,GraphServiceClient会产生NULL值。所以,你可能想要这个:

NULL