添加两个具有负值的sum case语句

时间:2016-08-31 13:23:58

标签: sql sql-server-2008

我正在尝试添加两个带有onyl负值的select语句,这些是语句:

SUM(CASE WHEN LinkAcc = '8420000' THEN amount < 0 END) 
SUM(CASE WHEN LinkAcc = '8400000' THEN amount < 0 END) AS Payments

我试过了:

    SUM(CASE WHEN LinkAcc = '8400000,8420000' THEN amount < 0 END) AS Payments

1 个答案:

答案 0 :(得分:4)

THEN amount < 0没有多大意义。如果我理解正确,你想要的是:

SUM(CASE 
       WHEN LinkAcc IN ('8420000','8400000') AND amount < 0 
       THEN amount 
    END) As Payments