Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to include another data to existing pivot?

2633101Nov 21 2014 — edited Nov 21 2014

Hi, I have this query:

select *

from (

        SELECT 'RD',

               '1001142302',

               defmac.COD_MACHIN,

               machine.NUM_SERIE,

               dmag.HARDWAR_ID,

               contadores.COD_CPTE,

               contadores.VAL_CPT_OL,

               defmac.PCT_REDIST,

               case when mensajes.COD_MSG_OL = 'MDC_DISCON' then '01'

                    when mensajes.COD_MSG_OL = 'SM_DISCON' then '02'

                    when mensajes.COD_MSG_OL = 'SM_NVRAM_ERROR' then '03'

                    when mensajes.COD_MSG_OL = '1397' then '04'

                    when mensajes.COD_MSG_OL = 'EPROM_CHANGE' then '05'

                    when mensajes.COD_MSG_OL = 'SM_POWER_OFF' then '06'

                    when mensajes.COD_MSG_OL = '1402' then '07'

                    when mensajes.COD_MSG_OL = '1405' then '07'

                    when mensajes.COD_MSG_OL = '1406' then '07'

                    when mensajes.COD_MSG_OL = '1408' then '07'

                    when mensajes.COD_MSG_OL = '1412' then '07'

                    when mensajes.COD_MSG_OL = '1413' then '07'

                    when mensajes.COD_MSG_OL = '1414' then '07'

                    when mensajes.COD_MSG_OL = '1415' then '07'

                    when mensajes.COD_MSG_OL = '1419' then '07'

                    when mensajes.COD_MSG_OL = '1431' then '07'

                    when mensajes.COD_MSG_OL = '1432' then '07'

                    when mensajes.COD_MSG_OL = 'WRAP_CI' then '07'

                    when mensajes.COD_MSG_OL = 'WRAP_CO' then '07'

                    when mensajes.COD_MSG_OL = 'WRAP_CTC' then '07'

                    when mensajes.COD_MSG_OL = 'WRAP_DOPPAY' then '07'

                    when mensajes.COD_MSG_OL = 'WRAP_GM' then '07'

                    when mensajes.COD_MSG_OL = 'WRAP_TI' then '07'

                    when mensajes.COD_MSG_OL = 'WRAP_TO' then '07'

                    when mensajes.COD_MSG_OL = '1399' then '08'

                    else '00'

                    end as "CODIGO"

        FROM site.sdefmac defmac

        inner join SITE.smachin machine on defmac.COD_MACHIN = machine.COD_MACHIN

        inner join SITE.SDEFMAG dmag on defmac.COD_MACHIN = dmag.COD_MACHIN

        inner join SITE.SLCOMPT contadores on defmac.COD_MACHIN = contadores.COD_MACHIN

        inner join SITE.SHISMSG mensajes on defmac.COD_MACHIN = mensajes.COD_OBJ

        where (defmac.DAT_EDEF IS NULL or defmac.COD_MEP = 1)

        AND defmac.COD_ETATSN = '0'

        AND dmag.cod_mep = '1'

        AND (contadores.dat_ses = '2013-09-15 00:00:00'

        AND (contadores.COD_CPTE in ('TI', 'TO', 'JP', 'HP', 'BI', 'GM')))

        AND mensajes.COD_MSG_OL in ('MDC_DISCON', 'SM_DISCON', '1397', 'EPROM_CHANGE', 'SM_NVRAM_ERROR', 'SM_POWER_OFF', '1402', '1405',

        '1406', '1408', '1412', '1413', '1414', '1415', '1419', '1431', '1432', 'WRAP_CI', 'WRAP_CO', 'WRAP_CTC', 'WRAP_DOPPAY',

        'WRAP_GM', 'WRAP_TI', 'WRAP_TO', '1399')

     )

     pivot

            (

             max(VAL_CPT_OL)

             for COD_CPTE in ('TI', 'TO', 'JP', 'HP', 'BI', 'GM')

            ) order by COD_MACHIN, CODIGO;

Here is a sample of the result of this query:

RD1001142302  COD_MACHINNUM_SERIEHARDWAR_IDPCT_REDISTCODIGOTITOJPHPBIGM
RD1001142302  AT020112231010013580256274100012332187220681467192206021570157426800379082
RD1001142302AT020112231010013580256274100082332187220681467192206021570157426800379082

But, what I want to do is to put the column CODIGO in this way

RD1001142302  COD_MACHINNUM_SERIEHARDWAR_IDPCT_REDISTTITOJPHPBIGMCOD1COD2
RD1001142302  AT02011223101001358025627410023321872206814671922060215701574268003790820108

Is this possible?

Thanks.

Message was edited by: 2633101 I solved the problem, Just include my query inside another select * from ( MY QUERY) PIVOT (); Thanks.

Comments

Can you please have a look at the VS Code Windowing options to see if any of them do what you want?
In the VS Code menu, select View->Editor Layout

User_ZZQ0F

Everytime I run query I use shortcut Ctrl+Alt+Right to split pane.
Would be nice to do make it automatically.

1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 19 2014
Added on Nov 21 2014
1 comment
509 views