原始数据是这样的
希望能按周数进行列分组,
单个的分组我知道用decode或者case when都可以,
但是我有多个数据
想请教怎么写
希望得到的结果
------解决思路----------------------
with Tb as (
select 'A组' mc,'1' as zs,3 as js,'马克思' as kc from dual union all
select 'A组' mc,'1' as zs,1 as js,'烹饪' as kc from dual union all
select 'A组' mc,'1' as zs,2 as js,'列毛' as kc from dual union all
select 'A组' mc,'3' as zs,1 as js,'XX学' as kc from dual union all
select 'C组' mc,'3' as zs,2 as js,'物理' as kc from dual union all
select 'B组' mc,'1' as zs,2 as js,'历史' as kc from dual union all
select 'C组' mc,'1' as zs,2 as js,'挖掘机' as kc from dual union all
select 'B组' mc,'3' as zs,1 as js,'政治' as kc from dual union all
select 'B组' mc,'2' as zs,3 as js,'生物' as kc from dual union all
select 'C组' mc,'2' as zs,1 as js,'化学' as kc from dual union all
select 'B组' mc,'3' as zs,2 as js,'计算机' as kc from dual)
select A.mc as zs1_mc,A.js as zs1_js,A.kc as zs1_kc,B.mc as zs2_mc,B.js as zs2_js,B.kc as zs_kc,C.mc as zs3_mc,C.js as zs3_js,C.kc as zs3_kc
from (select rownum rn,mc,zs,js,kc from tb where zs=1 order by 2) A
full outer join (select rownum rn,mc,zs,js,kc from tb where zs=2 order by 2) B on A.rn=B.rn
full outer join (select rownum rn,mc,zs,js,kc from tb where zs=3 order by 2) C on A.rn=C.rn
------解决思路----------------------
如果数据库版本在11以上的话,可以用下面的方式简单处理(如果不是的话,建议用函数实现。