我也想知道 。ding !!!,

解决方案 »

  1.   

    如果是交叉报表的形式到是好做一点!如果就用SQL语句的话只能CASE WHEN
      

  2.   

    create table tab_A(rq varchar2(20),sp varchar2(10),sl varchar2(10));
    insert into tab_A(......)
    -----------------------------------------------------------------------SELECT sp,SUM(decode(rq,'2005年1月1日',sl,'0')) "2005年1月1日",
              SUM(decode(rq,'2005年1月2日',sl,'0')) "2005年1月2日",
              SUM(decode(rq,'2005年1月3日',sl,'0')) "2005年1月3日",
              SUM(decode(rq,'2005年1月4日',sl,'0')) "2005年1月4日"
    FROM tab_A
    GROUP BY sp;
      

  3.   

    你这个需求基本上就是行列转换,用decode函数可以完成。
    参考下面两个例子:Q: 如何实现行列转换 
    A:  1. 固定列数的行列转换 
        
    student     subject   grade 
    --------    -------   ----- 
    student1    语文       80 
    student1    数学       70 
    student1    英语       60 
    student2    语文       90 
    student2    数学       80 
    student2    英语       70 转换为: 
    student   语文  数学  英语 
    student1  80    70    60 
    student2  90    80    70 SQl>create table student(id number,name varchar2(20), subject varchar2(20),
     grade number(3)) nologging;
     
     insert into student values(1,'张三','语文',80);
     insert into student values(1,'张三','数学',70);
     insert into student values(1,'张三','英语',60);
     
     insert into student values(2,'李四','语文',90);
     insert into student values(2,'李四','数学',80);
     insert into student values(2,'李四','英语',70);
    SQL>select id,name,sum(decode(subject,'语文', grade,null)) As "语文", 
                   sum(decode(subject,'数学', grade,null)) As "数学", 
                   sum(decode(subject,'英语', grade,null)) As "英语" 
           from student
           group by id,name 
          
     
      2.  不定列行列转换 
          
           c1    c2 
           ---  ---
           1    我 
           1    是 
           1    谁 
           2    知 
           2    道 
           3    不 
     
          转换为: 
           1    我是谁 
           2    知道 
           3    不 这一类型的转换必须借助于PL/SQL来完成,这里给一个例子 CREATE OR REPLACE FUNCTION get_c2(tmp_c1 NUMBER) 
    RETURN VARCHAR2 
    IS 
    Col_c2 VARCHAR2(4000); 
    BEGIN 
    FOR cur IN (SELECT c2 FROM t WHERE c1=tmp_c1) LOOP 
    Col_c2 := Col_c2||cur.c2; 
    END LOOP; 
    Col_c2 := rtrim(Col_c2,1); 
    RETURN Col_c2; 
    END; 
    / SQL> select distinct c1 ,get_c2(c1) cc2 from table;
      

  4.   

    SELECT SP00,SUM(decode(RQ00,'2005年1月1日',SL00,0)) "2005年1月1日",
                SUM(decode(RQ00,'2005年1月2日',SL00,0)) "2005年1月2日",
                SUM(decode(RQ00,'2005年1月3日',SL00,0)) "2005年1月3日",
                SUM(decode(RQ00,'2005年1月4日',SL00,0)) "2005年1月4日"
    FROM A
    GROUP BY SP00;
      

  5.   

    select
    sp00,
    sum(decode(rq00,'2005年1月1日',sl00,0)),
    sum(decode(rq00,'2005年1月2日',sl00,0)),
    sum(decode(rq00,'2005年1月3日',sl00,0)),
    sum(decode(rq00,'2005年1月4日',sl00,0))
    from a
    group by sp00
      

  6.   

    select sp00,
               sum(decode(rq00,'2005年1月1日',sl00,0)) "2005年1月1日",
               sum(decode(rq00,'2005年1月2日',sl00,0)) "2005年1月2日",
               sum(decode(rq00,'2005年1月3日',sl00,0)) "2005年1月3日",
               sum(decode(rq00,'2005年1月4日',sl00,0)) "2005年1月4日"
    from  A
    group by sp00;
      

  7.   

    行列轉換的說,大家都很厲害呀推薦:SQL行列转换实战
    http://www.cnoug.org/viewthread.php?tid=21713