sql >> データベース >  >> RDS >> Oracle

Oracleは行を列に変換します

    Oracleで行から列に移動するすべての可能性については、ここで読むことができます:

    http://www.dba-oracle.com/t_converting_rows_columns.htm

    データベースの観点からは、そのための簡単な解決策は見当たりません。アプリケーション側でフォーマットを行うことをお勧めします。そうしないと、次のように不十分に見える可能性があります。

    SELECT
       to_char(w1.w_Date,'MM/DD/YYYY'), to_char(w2.w_Date,'MM/DD/YYYY'), 
       to_char(w3.w_Date,'MM/DD/YYYY'), to_char(w4.w_Date,'MM/DD/YYYY')
    FROM 
     (select * from weather where w_date = trunc(sysdate)) w1,
     (select * from weather where w_date = trunc(sysdate) + 1) w2,
     (select * from weather where w_date = trunc(sysdate) + 2) w3,
     (select * from weather where w_date = trunc(sysdate) + 3) w4
    UNION ALL
    SELECT
       w1.image,  w2.image, w3.image , w4.image
    FROM 
     (select * from weather where w_date = trunc(sysdate)) w1,
     (select * from weather where w_date = trunc(sysdate) + 1) w2,
     (select * from weather where w_date = trunc(sysdate) + 2) w3,
     (select * from weather where w_date = trunc(sysdate) + 3) w4
    UNION ALL
    SELECT
       w1.w_type,  w2.w_type, w3.w_type , w4.w_type
    FROM 
     (select * from weather where w_date = trunc(sysdate)) w1,
     (select * from weather where w_date = trunc(sysdate) + 1) w2,
     (select * from weather where w_date = trunc(sysdate) + 2) w3,
     (select * from weather where w_date = trunc(sysdate) + 3) w4
    UNION ALL
    SELECT
       to_char(w1.high),  to_char(w2.high), to_char(w3.high) , to_char(w4.high)
    FROM 
     (select * from weather where w_date = trunc(sysdate)) w1,
     (select * from weather where w_date = trunc(sysdate) + 1) w2,
     (select * from weather where w_date = trunc(sysdate) + 2) w3,
     (select * from weather where w_date = trunc(sysdate) + 3) w4
    UNION ALL
    SELECT
       to_char(w1.low),  to_char(w2.low), to_char(w3.low) , to_char(w4.low)
    FROM 
     (select * from weather where w_date = trunc(sysdate)) w1,
     (select * from weather where w_date = trunc(sysdate) + 1) w2,
     (select * from weather where w_date = trunc(sysdate) + 2) w3,
     (select * from weather where w_date = trunc(sysdate) + 3) w4;
    /
    



    1. SybaseASE15.5の自律トランザクション

    2. インデックスを使用不可にしてからインデックスに再構築する方法

    3. コマンドラインからpostgresqlで認証失敗エラーを取得しています

    4. データソース接続を適切に閉じる方法は?