Oracle 11g - Unpivot

前端 未结 1 1544
清酒与你
清酒与你 2020-12-07 04:02

I have a table like this

Date        Year    Month   Day     Turn_1  Turn_2  Turn_3
28/08/2014  2014    08      28      Foo     Bar     Xab

相关标签:
1条回答
  • 2020-12-07 04:49

    Use this query:

    with t (Dat, Year, Month, Day, Turn_1, Turn_2, Turn_3) as (
      select sysdate, 2014, 08, 28, 'Foo', 'Bar', 'Xab' from dual
    )
    select dat, year, month, day, turn, source from t
    unpivot (
      source  for turn in (Turn_1, Turn_2, Turn_3)
    )
    
    DAT         YEAR    MONTH   DAY TURN    SOURCE
    ----------------------------------------------
    08/01/2014  2014    8       28  TURN_1  Foo
    08/01/2014  2014    8       28  TURN_2  Bar
    08/01/2014  2014    8       28  TURN_3  Xab
    
    0 讨论(0)
提交回复
热议问题