SELECT
        amor.ID_BV,
        amor.DESCRIPCION as ESTUDIO,
         amor.TE as T_E,
        amor.NIVEL AS NIVEL,
        amor.MES_1 as AMOR_1,
        visual.MES_1 as VIS_1,
        DECODE( visual.MES_1, 0, 0, ROUND( amor.MES_1 / visual.MES_1, 2 ) ) as CPV_1,
        amor.MES_2 as AMOR_2,
        visual.MES_2 as VIS_2,
        DECODE( visual.MES_2, 0, 0, ROUND( CASE WHEN amor.MES_2 IS NULL OR amor.MES_2 = 0  THEN amor.MES_1 ELSE amor.MES_2 END / visual.MES_2, 2 ) ) as CPV_2,
        amor.MES_3 as AMOR_3,
        visual.MES_3 as VIS_3,
        DECODE( visual.MES_3, 0, 0, ROUND( CASE WHEN amor.MES_3 IS NULL OR amor.MES_3 = 0  THEN amor.MES_2 ELSE amor.MES_3 END  / visual.MES_3, 2 ) ) as CPV_3,
        amor.MES_4 as AMOR_4,
        visual.MES_4 as VIS_4,
        DECODE( visual.MES_4, 0, 0, ROUND( CASE WHEN amor.MES_4 IS NULL OR amor.MES_4 = 0  THEN amor.MES_3 ELSE amor.MES_4 END  / visual.MES_4, 2 ) ) as CPV_4,
        amor.MES_5 as AMOR_5,
        visual.MES_5 as VIS_5,
        DECODE( visual.MES_5, 0, 0, ROUND( CASE WHEN amor.MES_5 IS NULL OR amor.MES_5 = 0  THEN amor.MES_4 ELSE amor.MES_5 END  / visual.MES_5, 2 ) ) as CPV_5,
        amor.MES_6 as AMOR_6,
        visual.MES_6 as VIS_6,
        DECODE( visual.MES_6, 0, 0,  ROUND( CASE WHEN amor.MES_6 IS NULL OR amor.MES_6 = 0  THEN amor.MES_5 ELSE amor.MES_6 END  / visual.MES_6, 2 ) ) as CPV_6,
        amor.MES_7 as AMOR_7,
        visual.MES_7 as VIS_7,
        DECODE( visual.MES_7, 0, 0, ROUND( CASE WHEN amor.MES_7 IS NULL OR amor.MES_7 = 0  THEN amor.MES_6 ELSE amor.MES_7 END  / visual.MES_7, 2 ) ) as CPV_7,
        amor.MES_8 as AMOR_8,
        visual.MES_8 as VIS_8,
        DECODE( visual.MES_8, 0, 0, ROUND( CASE WHEN amor.MES_8 IS NULL OR amor.MES_8 = 0  THEN amor.MES_7 ELSE amor.MES_8 END  / visual.MES_8, 2 ) ) as CPV_8,
        amor.MES_9 as AMOR_9,
        visual.MES_9 as VIS_9,
        DECODE( visual.MES_9, 0, 0, ROUND( CASE WHEN amor.MES_9 IS NULL OR amor.MES_9 = 0  THEN amor.MES_8 ELSE amor.MES_9 END  / visual.MES_9, 2 ) ) as CPV_9,
        amor.MES_10 as AMOR_10,
        visual.MES_10 as VIS_10,
        DECODE( visual.MES_10, 0, 0, ROUND( CASE WHEN amor.MES_10 IS NULL OR amor.MES_10 = 0  THEN amor.MES_9 ELSE amor.MES_10 END  / visual.MES_10, 2 ) ) as CPV_10,
        amor.MES_11 as AMOR_11,
        visual.MES_11 as VIS_11,
        DECODE( visual.MES_11, 0, 0, ROUND( CASE WHEN amor.MES_11 IS NULL OR amor.MES_11 = 0  THEN amor.MES_10 ELSE amor.MES_11 END  / visual.MES_11, 2 ) ) as CPV_11,
        amor.MES_12 as AMOR_12,
        visual.MES_12 as VIS_12,
        DECODE( visual.MES_12, 0, 0, ROUND( CASE WHEN amor.MES_12 IS NULL OR amor.MES_12 = 0  THEN amor.MES_11 ELSE amor.MES_12 END  / visual.MES_12, 2 ) ) as CPV_12
    FROM
      (
           SELECT
                CASE
                   WHEN DESC_ESTUDIO IS NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL THEN
                  ''
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL THEN
                  'Estudio'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL THEN
                  'Titulo'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NOT NULL AND ID_BV IS NOT NULL THEN
                  ID_BV 
                END as ID_BV,
                DESC_ESTUDIO,
                NOMBRE_UNICO,
                DESC_TITULO,
                TEMPORADA, EPISODIO,
                CASE
                   WHEN DESC_ESTUDIO IS NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL THEN
                  0
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL THEN
                  1
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL THEN
                  2
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NOT NULL THEN
                  3              
                END as NIVEL,
                CASE 
                   WHEN DESC_ESTUDIO IS NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  1
                   ELSE
                  0               
                END as ORDEN_N1,
                CASE 
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  1
                   ELSE
                  0               
                END as ORDEN_N2,
                CASE 
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NOT NULL AND EPISODIO IS NULL THEN
                  1
                   ELSE
                  0               
                END as ORDEN_N3,
                CASE 
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NOT NULL THEN
                  1
                   ELSE
                  0               
                END as ORDEN_N4,
                CASE
                   WHEN DESC_ESTUDIO IS NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  'TOTAL'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  DESC_ESTUDIO
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  NOMBRE_UNICO
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NOT NULL AND EPISODIO IS NULL THEN
                  NOMBRE_UNICO || ' Temporada '|| temporada
				   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NOT NULL THEN
                  NOMBRE_UNICO || ' Temporada Unica'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NOT NULL AND ID_BV IS NOT NULL THEN
                  DESC_TITULO  
                END as DESCRIPCION,
                CASE
                  WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND ID_BV IS NULL AND TEMPORADA IS NOT NULL AND EPISODIO IS NULL THEN
                  'Temporada '|| TEMPORADA
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NOT NULL AND ID_BV IS NOT NULL AND TEMPORADA IS NOT NULL AND EPISODIO IS NOT NULL THEN
                  EPISODIO
                END as TE,
                CASE
                   WHEN DESC_ESTUDIO IS NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  'TOTAL'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  DESC_ESTUDIO
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  NOMBRE_UNICO
				   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NOT NULL AND EPISODIO IS NULL THEN
                  NOMBRE_UNICO || ' Temporada '|| temporada
				   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NOT NULL THEN
                  NOMBRE_UNICO || ' Temporada Unica'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NOT NULL AND ID_BV IS NOT NULL THEN
                   DESC_ESTUDIO || ' ' || DESC_TITULO || ' ' || ID_BV
                END as JOINING,
                ROUND( SUM( MES_1 ), 2 ) as MES_1, 
                ROUND( SUM( MES_2 ), 2 ) as MES_2, 
                ROUND( SUM( MES_3 ), 2 ) as MES_3, 
                ROUND( SUM( MES_4 ), 2 ) as MES_4, 
                ROUND( SUM( MES_5 ), 2 ) as MES_5, 
                ROUND( SUM( MES_6 ), 2 ) as MES_6, 
                ROUND( SUM( MES_7 ), 2 ) as MES_7, 
                ROUND( SUM( MES_8 ), 2 ) as MES_8, 
                ROUND( SUM( MES_9 ), 2 ) as MES_9, 
                ROUND( SUM( MES_10 ), 2 ) as MES_10, 
                ROUND( SUM( MES_11 ), 2 ) as MES_11, 
                ROUND( SUM( MES_12 ), 2 ) as MES_12
           FROM 
                (
                        SELECT
                            DESC_ESTUDIO, ANNIO, DESC_TITULO, NOMBRE_UNICO, ID_BV, TEMPORADA, EPISODIO,
                            NVL( MES_1, 0 ) as MES_1, NVL( MES_2, 0 ) as MES_2, 
                            NVL( MES_3, 0 ) as MES_3, NVL( MES_4, 0 ) as MES_4, 
                            NVL( MES_5, 0 ) as MES_5, NVL( MES_6, 0 ) as MES_6, 
                            NVL( MES_7, 0 ) as MES_7, NVL( MES_8, 0 ) as MES_8, 
                            NVL( MES_9, 0 ) as MES_9, NVL( MES_10, 0 ) as MES_10, 
                            NVL( MES_11, 0 ) as MES_11, NVL( MES_12, 0 ) as MES_12
                        FROM
                        (
                            SELECT       
                                est.DESC_ESTUDIO,
                                amor.ID_TITULO_CNTORIG,  
                                ct.ID_BV,
                               ct.TEMPORADA,
                                ct.EPISODIO,
                                ct.DESC_TITULO,
                                ct.NOMBRE_UNICO,
                                TO_NUMBER( TO_CHAR( amor.MES, 'yyyy' ) ) as ANNIO,
                                TO_NUMBER( TO_CHAR( amor.MES, 'mm' ) ) as MESES, 
                                TO_NUMBER( amor.MONTO ) as MONTO
                            FROM
                                DDA_T_AMORTIZACIONCPV amor
                                INNER JOIN ( 
                                    SELECT 
                                    scnt.ID_CONTRATO_ORIGINAL AS ID_CONTRATO,
                                    ct.ID_TITULO_CNTORIG,
                                    ct.ID_BV,
                                    ct.DESC_TITULO,
                                    ct.NOMBRE_UNICO,
                                    ct.TEMPORADA,
                                    ct.EPISODIO,
                                    ct.FECHA_INICIO,
                                    ct.FECHA_FIN,
                                    ct.COSTO
                                    FROM DDA_T_CONTRATO_TITULO ct
                                    INNER JOIN
                                         (SELECT ID_CONTRATO_ORIGINAL,
                                          MAX( ID_CONTRATO ) AS ID_CONTRATO
                                          FROM DDA_T_CONTRATO
                                          WHERE ID_TIPO_CONTRATO = 1
                                          GROUP BY ID_CONTRATO_ORIGINAL) scnt
                                    ON ct.ID_CONTRATO = scnt.ID_CONTRATO
                                    INNER JOIN DDA_C_CATEGORIA c ON ct.ID_CATEGORIA_TIT = c.ID_CATEGORIA
                                    ) 
                                ct on ct.ID_TITULO_CNTORIG = amor.ID_TITULO_CNTORIG
                                INNER JOIN  DDA_T_CONTRATO cnt on cnt.ID_CONTRATO = amor.ID_CONTRATO_ORIGINAL  
                                       AND  cnt.ID_CONTRATO = ct.ID_CONTRATO
                                INNER JOIN DDA_C_ESTUDIO est on est.ID_ESTUDIO = cnt.ID_ESTUDIO 
                            WHERE                                 
                                TO_DATE( TO_CHAR( amor.MES, 'mm-yyyy' ), 'mm-yyyy' ) <= TO_DATE(#{mes} || '-' || #{anio}, 'mm-yyyy' )
                                AND TO_NUMBER( TO_CHAR( amor.MES, 'yyyy' ) ) = #{anio}
                                AND cnt.ID_ESTATUS in ( 4, 5, 6 )
                        )
                        PIVOT( SUM( MONTO ) FOR 
                            MESES in ( 1 as MES_1, 2 as MES_2, 3 as MES_3, 4 as MES_4, 5 as MES_5, 6 as MES_6,
                                        7 as MES_7, 8 as MES_8, 9 as MES_9, 10 as MES_10, 11 as MES_11, 12 as MES_12 )
                            )                            
           )GROUP BY
                GROUPING SETS
                    ( 
                        ( ),
                        (DESC_ESTUDIO),
                        (DESC_ESTUDIO, NOMBRE_UNICO, TEMPORADA ),
                        (DESC_ESTUDIO, NOMBRE_UNICO, DESC_TITULO,  TEMPORADA, EPISODIO, ID_BV )
                    )
      ) amor,
      (
           SELECT 
                CASE
                   WHEN DESC_ESTUDIO IS NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  'TOTAL'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  DESC_ESTUDIO
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  NOMBRE_UNICO
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NOT NULL AND EPISODIO IS NULL THEN
                  NOMBRE_UNICO || ' Temporada '|| temporada
				   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NOT NULL THEN
                  NOMBRE_UNICO || ' Temporada Unica'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NOT NULL AND ID_BV IS NOT NULL THEN
                  DESC_TITULO              
                END as DESCRIPCION,
                TEMPORADA, EPISODIO,
                CASE
                  WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND ID_BV IS NULL AND TEMPORADA IS NOT NULL AND EPISODIO IS NULL THEN
                  'Temporada '|| TEMPORADA
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NOT NULL AND ID_BV IS NOT NULL AND TEMPORADA IS NOT NULL AND EPISODIO IS NOT NULL THEN
                  EPISODIO
                END as TE,
                CASE
                   WHEN DESC_ESTUDIO IS NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  'TOTAL'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  DESC_ESTUDIO
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NULL THEN
                  NOMBRE_UNICO
				   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NOT NULL AND EPISODIO IS NULL THEN
                  NOMBRE_UNICO || ' Temporada '|| temporada
				   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NULL AND TEMPORADA IS NULL AND EPISODIO IS NOT NULL THEN
                  NOMBRE_UNICO || ' Temporada Unica'
                   WHEN DESC_ESTUDIO IS NOT NULL AND NOMBRE_UNICO IS NOT NULL AND DESC_TITULO IS NOT NULL AND ID_BV IS NOT NULL THEN
                   DESC_ESTUDIO || ' ' || DESC_TITULO || ' ' || ID_BV
                END as JOINING,
                SUM( MES_1 ) as MES_1, SUM( MES_2 ) as MES_2, SUM( MES_3 ) as MES_3, SUM( MES_4 ) as MES_4, SUM( MES_5 ) as MES_5, SUM( MES_6 ) as MES_6,
                SUM( MES_7 ) as MES_7, SUM( MES_8 ) as MES_8, SUM( MES_9 ) as MES_9, SUM( MES_10 ) as MES_10, SUM( MES_11 ) as MES_11, SUM( MES_12 ) as MES_12
           FROM 
            (
                SELECT
                    DESC_ESTUDIO, 
                    DESC_TITULO,
                    NOMBRE_UNICO, ID_BV, TEMPORADA, EPISODIO, -- ES_SERIE,
                    NVL( MES_1, 0 ) as MES_1, NVL( MES_2, 0 ) as MES_2, 
                    NVL( MES_3, 0 ) as MES_3, NVL( MES_4, 0 ) as MES_4, 
                    NVL( MES_5, 0 ) as MES_5, NVL( MES_6, 0 ) as MES_6, 
                    NVL( MES_7, 0 ) as MES_7, NVL( MES_8, 0 ) as MES_8, 
                    NVL( MES_9, 0 ) as MES_9, NVL( MES_10, 0 ) as MES_10, 
                    NVL( MES_11, 0 ) as MES_11, NVL( MES_12, 0 ) as MES_12
                FROM
                (
                    SELECT
                        e.DESC_ESTUDIO,  vc.ID_BV,
                        vc.DESC_TITULO, vc.NOMBRE_UNICO, vc.TEMPORADA, vc.EPISODIO,
                        TO_NUMBER( TO_CHAR( vc.MES, 'yyyy' ) ) as ANNIO,
                        TO_NUMBER( TO_CHAR( vc.MES, 'mm' ) ) as MESES, 
                        SUM( vc.CANTIDAD ) as TOTAL
                    FROM
                        (  
                          WITH base_query AS (      
                             SELECT  ct.ID_LISTA, ct.ID_BV, ct.ID_ESTUDIO, v.MES, v.CANTIDAD, ct.NOMBRE_UNICO, ct.DESC_TITULO, ct.TEMPORADA, ct.EPISODIO
                             FROM  DDA_T_VISUALIZACION v
                               INNER JOIN(   
                                 SELECT  t.ID_LISTA, t.ID_BV, c.ID_ESTUDIO, t.FECHA_INICIO, t.FECHA_FIN, t.NOMBRE_UNICO, t.DESC_TITULO,
								 t.TEMPORADA, t.EPISODIO
                                 FROM DDA_T_CONTRATO_TITULO t
                                   INNER JOIN DDA_T_CONTRATO c on c.ID_CONTRATO = t.ID_CONTRATO
                                   INNER JOIN DDA_C_CATEGORIA cat ON t.ID_CATEGORIA_TIT = cat.ID_CATEGORIA
                                 WHERE c.ID_ESTATUS in ( 4, 5, 6 )
                               )ct ON ct.ID_BV = v.ID_BV
                             WHERE v.MES BETWEEN ADD_MONTHS((LAST_DAY(ct.FECHA_INICIO)+1),-1) AND LAST_DAY(ct.FECHA_FIN)
                                  AND TO_DATE( TO_CHAR( v.MES, 'mm-yyyy' ), 'mm-yyyy' ) <= TO_DATE(#{mes} || '-' ||#{anio}, 'mm-yyyy' )                 
                                  AND TO_NUMBER( TO_CHAR( v.MES, 'yyyy' ) ) = #{anio}
                          )
                           SELECT DISTINCT a.ID_BV, a.ID_ESTUDIO, a.MES, a.CANTIDAD, a.NOMBRE_UNICO, a.DESC_TITULO, a.TEMPORADA, a.EPISODIO --, a.ES_SERIE
                           FROM base_query a
                             INNER JOIN (
                               SELECT ID_BV, ID_ESTUDIO, MES, MAX(ID_LISTA) AS ID_LISTA  FROM base_query 
                               GROUP BY ID_BV, ID_ESTUDIO, MES
                           ) b ON a.ID_BV = b.ID_BV AND a.MES = b.MES AND a.ID_ESTUDIO = b.ID_ESTUDIO AND a.ID_LISTA = b.ID_LISTA 
                        ) vc
                        INNER JOIN DDA_C_ESTUDIO e ON e.ID_ESTUDIO = vc.ID_ESTUDIO 
                    GROUP BY e.DESC_ESTUDIO, vc.MES, vc.DESC_TITULO, vc.NOMBRE_UNICO, vc.ID_BV, vc.TEMPORADA, vc.EPISODIO--, vc.ES_SERIE
                )
                PIVOT( SUM( TOTAL ) FOR 
                    MESES in ( 1 as MES_1, 2 as MES_2, 3 as MES_3, 4 as MES_4, 5 as MES_5, 6 as MES_6,
                                7 as MES_7, 8 as MES_8, 9 as MES_9, 10 as MES_10, 11 as MES_11, 12 as MES_12 )
                    )   
            )GROUP BY
                GROUPING SETS
                (
                      ( ),
                      (DESC_ESTUDIO),
                      (DESC_ESTUDIO, NOMBRE_UNICO, TEMPORADA ),
                      (DESC_ESTUDIO, NOMBRE_UNICO, DESC_TITULO,  TEMPORADA, EPISODIO, ID_BV )
                )
      ) visual
    WHERE
      amor.JOINING = visual.JOINING (+) 
    ORDER BY ORDEN_N1, DESC_ESTUDIO, ORDEN_N2 DESC, NOMBRE_UNICO, decode(is_number(amor.TEMPORADA),0,0,to_number(amor.TEMPORADA)), ORDEN_N3 DESC, decode(is_number(amor.episodio),0,0,to_number(amor.episodio)), DESC_TITULO DESC, ORDEN_N4 DESC 