(总和(当国籍!='沙特'和DIVISION='达曼中央'并且状态为空然后(current_salary(结束((-(总和(当国籍!='沙特'和分区='达曼中央'和internal_transfer_from的情况('达曼中央','达曼东','吉达SMPT','朱拜勒','hadeed MTO','Hadeed FPH','IBN Rushd'( 然后 (current_salary( 结束((+((总和(当国籍!='沙特'
和internal_transfer_from='达曼中央'然后(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,
注意:仅供参考 处理空值
use coalesce(fieldname,0( = caseum(fieldnames( = 0 then sum(( else sum(( end
上面的示例
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