Doubt in SQL query ORACLE

3

I'm thinking of doing a View for report development, and I ran into the following problem.

I would like to merge the columns PUBLIC1, PUBLIC2, PUBLIC3, PUBLIC4 into a single column.

Eg: AM0173 would have 2 lines

ID_3_ETAPA | PUBLIC
AM0173 | 2
AM0173 | 1

Can I do this on a select?

    
asked by anonymous 06.03.2017 / 14:22

1 answer

3

I managed using UNPIVOT

SELECT ID_3_ETAPA
     , PUBLICO 
  FROM MINHA_TABELA UNPIVOT ( PUBLICO FOR PUBLICO_COR IN ( PUBLICO1 AS '1'
                                                         , PUBLICO2 AS '2'
                                                         , PUBLICO3 AS '3'
                                                         , PUBLICO4 AS '4'))
    
06.03.2017 / 14:46