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

SQL rækker i kolonner

Du kan ikke opnå dette med transponering. prøv hellere at bruge natural full outer join

WITH T
    AS (SELECT
             P.*,
             ROW_NUMBER ( )
                 OVER (PARTITION BY PERSON, LEVELS ORDER BY LANGUAGE)
                 R
        FROM
             PROGRAMMER P)
SELECT
      PERSON,
      SENIOR,
      MID,
      JUNIOR
FROM
      (SELECT
            PERSON,
            R,
            LANGUAGE SENIOR
       FROM
            T
       WHERE
            LEVELS = 'SENIOR')
      NATURAL FULL OUTER JOIN (SELECT
                                PERSON,
                                R,
                                LANGUAGE MID
                          FROM
                                T
                          WHERE
                                LEVELS = 'MID')
      NATURAL FULL OUTER JOIN (SELECT
                                PERSON,
                                R,
                                LANGUAGE JUNIOR
                          FROM
                                T
                          WHERE
                                LEVELS = 'JUNIOR');

Du får

PERSON          SENIOR               MID                  JUNIOR              
--------------- -------------------- -------------------- --------------------
CARL            JAVA                 PHP                  VB.NET              
GARY                                 C#                                       
GARY                                 VB.NET                                   
RALPH           JAVASCRIPT                                RUBY                
RALPH           PHP                                                           

5 rows selected.


  1. Oracle Funktion til at returnere lighed mellem strenge

  2. MySQL fejl 1449:Brugeren angivet som definerer eksisterer ikke

  3. MySQL Database Service – Nye HeatWave-innovationer

  4. DB associative entiteter og indeksering