情况是这样的
我要一张表
BH               GZ(工种)     RS(人员数量)
PDA03116    注册兽医师 2
PDA03116 注册兽医师 3
PDA03116 无定级兽医 1
PDA03116 中级技工          2
PDA03116 初级技工          1
PDA03116 无定级技工 2
PDA03117        无定级技工        7
...........
...........
想转换成如下形式:
BH            j_0(注册兽医师) j_1(注册兽医师) j_2(无定级兽医) j_3(中级技工) j_4(初级技工) j_5(无定级技工)
PDA03116       2                   3              1              2          1            2
PDA03117      ....               ....        ......          .....       .....            7我用DECODE()函数怎么也没解决这个问题
BH 会重复
请赐教
还有谁有谁有 oracle的performance manager学习资料发一份(另外给分)
EMAIL:
[email protected] 

解决方案 »

  1.   

    PDA03116  注册兽医师 2 
    PDA03116 注册兽医师 3 
    这两行的"注册兽医师"是一样的?
      

  2.   

    情况是这样的 
    我要一张表 
    BH              GZ(工种)    RS(人员数量) 
    PDA03116       注册兽医师       3 
    PDA03116       无定级兽医       1 
    PDA03116       中级技工         2 
    PDA03116       初级技工         1 
    PDA03116       无定级技工       2 
    PDA03117       无定级技工       7 
    ........... 
    ........... 
    想转换成如下形式: 
    BH        j_1(注册兽医师) j_2(无定级兽医) j_3(中级技工) j_4(初级技工) j_5(无定级技工) 
    PDA03116         3              1              2           1        2 
    PDA03117       ....        ......          .....        .....         7 
      
    我用DECODE()函数怎么也没解决这个问题 
    BH 会重复 
    请赐教 
    还有谁有谁有 oracle的performance manager学习资料发一份(另外给分) 
    EMAIL: 
    [email protected] 
      

  3.   

    with test as (select 'PDA03116' BH,'注册兽医师' GZ,3 RS from dual
                union all
                select 'PDA03116' BH,'无定级兽医' GZ,1 RS from dual
                union all
                select 'PDA03116' BH,'中级技工' GZ,2 RS from dual
                union all
                select 'PDA03116' BH,'初级技工' GZ,1 RS from dual
                union all
                select 'PDA03116' BH,'无定级技工' GZ,2 RS from dual
                union all
                select 'PDA03117' BH,'无定级技工' GZ,7 RS from dual)
                select bh,sum(decode(gz,'注册兽医师',rs,0)) "j_1(注册兽医师)",
                sum(decode(gz,'无定级兽医',rs,0)) "j_2(无定级兽医)",
                sum(decode(gz,'中级技工',rs,0)) "j_3(中级技工)",
                 sum(decode(gz,'初级技工',rs,0)) "j_4(初级技工)",
                 sum(decode(gz,'无定级技工',rs,0)) "j_5(无定级技工)" from test
                group by bh;
                
      

  4.   

    select bh ,sum(decode(GZ,'注册兽医师',RS,0)) "j_1(注册兽医师)"
           ,sum(decode(GZ,'无定级兽医,RS,0)) "j_2(无定级兽医)"
    ....
    from  a
     group by bh
      

  5.   


    select Distinct t01,
           max(case a when '1' then t03 end) A,
           max(case a when '2' then t03 end) B,
           max(case a when '3' then t03 end) C,
           max(case a when '4' then t03 end) D,
           max(case a when '5' then t03 end) E,
           max(case a when '6' then t03 end) F,
           max(case a when '7' then t03 end) G
    from (
    select test.*,to_char(rownum) a from test)
    group by t01
      

  6.   

    1 PDA03116 注册兽医师 2
    2 PDA03116 注册兽医师 3
    3 PDA03116 无定级兽医 1
    4 PDA03116 中级技工 2
    5 PDA03116 初级技工 1
    6 PDA03117 无定级技工 2
    7 PDA03117 无定级技工 7表中的内容:
    select Distinct t01,
           max(case a when '1' then t03 end) A,
           max(case a when '2' then t03 end) B,
           max(case a when '3' then t03 end) C,
           max(case a when '4' then t03 end) D,
           max(case a when '5' then t03 end) E,
           max(case a when '6' then t03 end) F,
           max(case a when '7' then t03 end) G
    from (
    select test.*,to_char(rownum) a from test)
    group by t01RESULT:
    PDA03116 2 3 1 2 1
    PDA03117 2 7
      

  7.   

    DROP TABLE tt;
    CREATE TABLE tt(BH VARCHAR2(20),    GZ VARCHAR2(20),      RS VARCHAR2(20));
     
    INSERT INTO TT VALUES ('PDA03116', '注册兽医师', 3);
    INSERT INTO TT VALUES ('PDA03116', '无定级兽医', 1);
    INSERT INTO TT VALUES ('PDA03116', '中级技工', 2);
    INSERT INTO TT VALUES ('PDA03116', '初级技工 ', 1);
    INSERT INTO TT VALUES ('PDA03116', '无定级技工', 2);
    INSERT INTO TT VALUES ('PDA03117', '无定级技工', 7);
    COMMIT;
    SELECT BH,
           MAX(DECODE(GZ, '注册兽医师', RS)),
           MAX(DECODE(GZ, '无定级兽医', RS)),
           MAX(DECODE(GZ, '中级技工', RS)),
           MAX(DECODE(GZ, '初级技工', RS)),
           MAX(DECODE(GZ, '无定级技工', RS))
      FROM TT
     GROUP BY BH
     ORDER BY 1;