Place the value of one column in another column of different rows

0

I need to create a select where it is placed in value of one column in another column which belong to different rows, using the criteria of the type column.

In other words, place the value of column_one in column_dos when type is = 'B'. Type 'C' should not be placed in column_dos. For example

id  descripción  tipo    columna_uno    columna_dos
1   grain          A     1000   
2   beans          B                    1000 (valor perteneciente a la columna_uno)
3   sugar          C     2000

I'm trying something like this but I do not get the desired result

 SELECT id, decripcion, tipo, columna_uno, 
     CASE WHEN tipo = 'B' THEN columna_uno end columna_dos

Is it possible to do this and what would it be like?

Thank you very much for the help.

    
asked by bryannsi 01.06.2018 в 01:35
source

1 answer

0
SELECT id, decripcion, tipo, 
CASE WHEN tipo != 'B' THEN columna_uno ELSE NULL end columna_uno ,
CASE WHEN tipo = 'B' THEN columna_uno ELSE NULL end columna_dos from nametable;

as I understand it would be something like that

    
answered by 01.06.2018 в 04:37