'IF' in 'SELECT' statement - choose output value based on column values

后端 未结 7 2188
孤城傲影
孤城傲影 2020-11-22 04:24
SELECT id, amount FROM report

I need amount to be amount if report.type=\'P\' and -amount if

7条回答
  •  遇见更好的自我
    2020-11-22 04:38

    SELECT id, amount
    FROM report
    WHERE type='P'
    
    UNION
    
    SELECT id, (amount * -1) AS amount
    FROM report
    WHERE type = 'N'
    
    ORDER BY id;
    

提交回复
热议问题