2017-09-21 17 views
0

私は以下の構造とサンプルでtable1を持っています。テーブル2としてそれを示す必要があります。誰でもこれを助けてください。Oracle sqlまたはplsqlから行への変換

表1

id Month Days 
1 january 20 
2 january 19 
3 january 20 
4 january 21 
5 january 22 
6 january 23 
1 February 18 
2 February 17 
3 February 16 
4 February 15 
5 February 16 
6 February 18 
6 February 18 

表2:

id January February 
1 20 18 
2 19 17 
3 20 16 
4 21 15 
5 22 16 
6 23 18 

答えて

2
select id 
    , sum(case when month = 'January' then days end) as january 
    , sum(case when month = 'February' then days end) as february 
    from table1 
group by id; 
0

case文は、あなたのクエリの最適なソリューションを提供します:

select id, 
     sum(
     case when 
       month = 'January' then days 
           else '' end) as january, 
     sum(
     case when 
       month = 'February' then days 
           else '' end) as February  
    from table1 
group by id; 
関連する問題