case within select mysql

0

Following the migration of SYBASE to MySQL I have found the following case, a case within the select. I leave the example in case you could guide me how to do it. Thank you!!

select mvfg_cantidad * case mvfg_tipo_origen when 'P' then 1 else -1 end  w_mov   
          from mvfg_mvto_fungibles
         where mvfg_marca = p_marca and mvfg_modelo = p_modelo and mvfg_fecha >= p_fecha and
               ( ( mvfg_tipo_origen = 'P' and mvfg_origen = p_destino) or
                 ( mvfg_tipo_destino = 'P' and mvfg_destino = p_destino)) 
         order by mvfg_fecha desc;
    
asked by Oscar Marés Barrera 28.09.2018 в 12:17
source

1 answer

0

The CASE substitute in MySQL is the IF syntax:

IF(condition, value_if_true, value_if_false)

You should put the IF statement in parentheses.

CASE documentation

    
answered by 28.09.2018 в 12:37