日期:2014-05-17  浏览次数:20779 次

sql 分组查询求助

如上图数据显示

这是我想要得到的结果,请问sql语句该怎么写

等于就是前4列要做成一条数据,把MOS值,这个是指标,需要得到它下面的得分,上周期得分,同比值。然后写在一行上面

这是我写的sql语句,后面不知道该怎么写了,思索了一天了求大神解答
select 列1,列2,
 case  when 列3 not in ('同比','得分','上周期得分') then 列3 else null end label1,
 max(case  when 列3 = '得分' then result_field else null end) 得分, 
 max(case  when 列3 = '同比' then result_field else null end) 同比,
 max(case  when 列3 = '上周期得分' then result_field else null end) 上周期得分
from cfg_qa_scene group by 列1,列2,列3,result_field

这样写出来的结果是8条数据
SQL select label oracle

------解决方案--------------------
select 列1,列2,
 sum(case  when 列3 not in ('同比','得分','上周期得分') then 列3 else null end)列3,
 sum(case  when 列3 = '得分' then 列4 else null end) 得分, 
 sum(case  when 列3 = '上周期得分' then 列4 else null end) 上周期得分,
 sum(case  when 列3 = '同比' then 列4 else null end )同比
from cfg_qa_scene

------解决方案--------------------
with tt as
 (select t.*,
         case
           when rownum <= 3 then
            'MOS值'
           else
            '下载速率(KBps)'
         end 列5
    from cfg_qa_scene  t
   where t.列3 not in ('MOS值', '下载速率(KBps)'))
select 列1,
       列2,
       列5,
       max(case
             when 列3 = '得分' then
              列4
             else
              null
           end) 得分,
       max(case