with a as 
(select 'dev1' col1,'file1' col2,'5' col3 from dual 
  union all 
 select 'dev1' col1,'file2' col2,'6' col3 from dual
  union all 
  select 'dev2' col1,'file2' col2,'3' col3 from dual 
  union all 
  select 'dev2' col1,'file3' col2,'4' col3 from dual
  )
目标结果:列名:file1   file2   file3  ... .... ...合计
dev1     5       6                        11 
dev2             3       4                7
合计     5       9       4                18

解决方案 »

  1.   


    select col1,file1,file2,file3,file1+file2+file3 合计
    from
        (select nvl(col1,'合计') col1,
               sum(decode(col2,'file1',col3,0)) file1,
               sum(decode(col2,'file2',col3,0)) file2,
               sum(decode(col2,'file3',col3,0)) file3
        from a
        group by rollup(col1)
        order by col1)
        col1     file1   file2  file3   合计
    ----------------------------------------------
    1 dev1 5 6 0 11
    2 dev2 0 3 4 7
    3 合计 5 9 4 18
      

  2.   

    file1   file2  file3   有没有办法动态展示呢,不能确定具体的列数。
    具体就是有时候,可能是 file1 file2 file3 
    有时候,      又成了  file1 file2 file4 file5 
      

  3.   

    file1   file2  file3   列数如果不能固定呢。
    比如有时候  file1   file2  file3   是三列有时候可能 file1   file2  file7   file8   是四列   
      

  4.   

    在这里找到一个动态生成列的例子,谢谢了http://topic.csdn.net/u/20090716/08/41AFF84A-97F8-4E70-B932-E0EAC6EBBF03.html