Oracle
 sql >> Database >  >> RDS >> Oracle

Ruota più tabelle con valori predefiniti

Questa query può essere un buon inizio come base per ulteriori esperimenti:

With src As (
    SELECT  lmnt.element_name
        ,   lmnt.element_entry_id
        ,   nval.input_value_id
        ,   nval.screen_entry_value
--        ,   eval.name 
        ,   row_number() over (partition by lmnt.element_name, lmnt.element_entry_id
                               order by lmnt.element_name  ) rn
    FROM    XX_SAMPLE_ELEMENTS lmnt
        ,   XX_ENTRY_VALUES    nval
        ,   XX_ELEMENT_VALUES  eval
    where   lmnt.element_entry_id = nval.element_entry_id
    and     eval.INPUT_VALUE_ID = nval.INPUT_VALUE_ID          
    order by lmnt.element_name
)


SELECT * FROM src
PIVOT (
    max( input_value_id ) As input_value,
    min( screen_entry_value ) as screen_entry_value
    FOR (rn)
    IN (1,2,3,4,5)
)