workbooks_3

----主副号对应表打横
-- 找出这些主号对应的副号
create table tmp_lzw_zh_fhnew as
select
b.zh,
b.fh,
row_number() over(partition by b.zh
order by b.fh
) rn
from tmp_lzw_zh_fh b
;


create table tmp_lzw_zhfh_new nologging as
select zh ,
max(case when rn = 1 then fh
else '0'
end
) fu_1,
max(case when rn = 2 then fh
else '0'
end
) fu_2,
max(case when rn = 3 then fh
else '0'
end
) fu_3,
max(case when rn = 4 then fh
else '0'
end
) fu_4,
max(case when rn = 5 then fh
else '0'
end
) fu_5,
max(case when rn = 6 then fh
else '0'
end
) fu_6,
max(case when rn = 7 then fh
else '0'
end
) fu_7,
max(case when rn = 8 then fh
else '0'
end
) fu_8
from (
select zh,
fh,
row_number() over(partition by zh
order by fh
) rn
from tmp_lzw_zh_fhnew a
) t
group by zh
;

你可能感兴趣的:(OO)