Posted By: Anonymous
SELECT id, amount FROM report
amount to be
report.type='N'. How do I add this to the above query?
SELECT id, IF(type = 'P', amount, amount * -1) as amount FROM report
Additionally, you could handle when the condition is null. In the case of a null amount:
SELECT id, IF(type = 'P', IFNULL(amount,0), IFNULL(amount,0) * -1) as amount FROM report
IFNULL(amount,0) means when amount is not null return amount else return 0.