SELECT Id, IF(type = 'P1', amount, amount * -1) as amount
FROM report
If the condition is null, in the case of a null amount you can use this to handle it:
SELECT Id, IF(type = 'P1', IFNULL(amount,0), IFNULL(amount,0) * -1) as amount
FROM report
Are you interested in learning SQL from scratch! Have a look at this interesting video on SQL provided by Intellipaat:
In the Above code, IFNULL(amount,0) this means it will return amount if the amount is assigned not null but if the amount is assigned as null then it’ll result in ‘zero’.