Doubt in SQL ORACLE query

Asked

Viewed 103 times

3

I am thinking of making a View for the development of reports, and I bumped into the following problem.

inserir a descrição da imagem aqui

I would like to join columns PUBLICO1, PUBLICO2, PUBLICO3, PUBLICO4 in a single column.

Ex.: AM0173 would have 2 lines

ID_3_ETAPA | PUBLICO
AM0173         |       2
AM0173         |       1

I can do that in a select?

  • Thus the public column was null on all lines.

  • turn your comment into a response, so you can help other people.

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'))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.