(总和(国民的情况!='沙特'和DIVISION ='达曼中心'和STATUS为空然后(current_salary)结束)) - (总和(国民的情况!='沙特'和DIVISION ='达曼中央'和internal_transfer_from在('Dammam Central','Dammam East','Jeddah SMPT','Jubail','hadeed MTO','Hadeed FPH','IBN Rushd')然后(current_salary)结束))+((总和) NATIONALITY!='Saudi'和internal_transfer_from ='Dammam Central'然后(current_salary)结束)))作为Dammam_Central,
这是你想要的
isnull((sum (case when NATIONALITY != 'Saudi' and DIVISION='Dammam Central' and STATUS is null then (current_salary) end)),0)-
isnull((sum (case when NATIONALITY != 'Saudi' and DIVISION='Dammam Central' and internal_transfer_from in ('Dammam Central','Dammam East','Jeddah SMPT','Jubail','hadeed MTO','Hadeed FPH','IBN Rushd') then (current_salary) end)),0)+
isnull(((sum (case when NATIONALITY != 'Saudi' and internal_transfer_from='Dammam Central' then (current_salary) end))),0) as Dammam_Central,
注意:仅供参考Handling Nulls
使用coalesce(fieldname,0)= casesum(fieldnames)= 0然后sum()else sum()结束
以上样本
COALESCE(sum (case when NATIONALITY != 'Saudi' and DIVISION='Dammam Central' and STATUS is null then (current_salary) end)),0)- COALESCE(sum (case when NATIONALITY != 'Saudi' and DIVISION='Dammam Central' and internal_transfer_from in ('Dammam Central','Dammam East','Jeddah SMPT','Jubail','hadeed MTO','Hadeed FPH','IBN Rushd') then (current_salary) end)),0)+(COALESCE(sum (case when NATIONALITY != 'Saudi' and internal_transfer_from='Dammam Central' then (current_salary) end)),0) as Dammam_Central