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

后端 未结 7 2204
孤城傲影
孤城傲影 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:49

    You can try this also

     SELECT id , IF(type='p', IFNULL(amount,0), IFNULL(amount,0) * -1) as amount FROM table
    

提交回复
热议问题