I need in a select to add a field, so I need to check two conditions, if the currency is 3 divide by the exchange, if the operation is 18 take the whole sum and multiply by -1. The select I have does sum by checking the currency, but I can not put two checks to make negative when the operation is 18, because operation 18 is cancellation of registration.
SELECT SUM(IF(MOEDA=2,(VALOR/CAMBIO), VALOR)) VL FROM banco.CAIXA where DATA= '2018-11-06' AND OPERACAO IN(2,18)