MySQL Forums
Forum List  »  Spanish

Re: Insertar datos en nueva columna basado en condiciones de otras columnas
Posted by: Jesús Uzcanga
Date: April 12, 2018 09:58AM

Juan David, la forma más expedita de hacerlo es un único UPDATE con condicionales (CASE WHEN) pero yo recomiendo para usuario que están aprendiendo crear un UPDATE para cada caso.


Si la columna A=1 y B=4 entonces D='Amigo',


UPDATE tabla1
SET D='Amigo'
WHERE A=1 AND B=4;



si A=2 y B=4 entonces D='Enemigo',

UPDATE tabla1
SET D='Enemigo'
WHERE A=2 AND B=4;


si A no es ni 1 ni 2 y B=7 entonces D=C

UPDATE tabla1
SET D=C
WHERE A<>1 AND A<>2 AND B=7;

___________________________
Ing. Jesús Alfredo Uzcanga
Twitter: @JesusUzcanga

We learn the 20% of what we HEAR,
the 50% of what we SEE,
the 80% of what we DO and
the 95% of what we TEACH.

____________________________________________________________
https://www.linkedin.com/in/jauzcanga/

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.