17,089
社区成员
发帖
与我相关
我的任务
分享
with tb as(
select 'a' product, 1 bomid ,1 qnt, '压缩机' type from dual union all
select 'a' ,2 ,1 ,'压缩机' from dual union all
select 'a' ,3 ,2 ,'电机' from dual union all
select 'b' ,4 ,1 ,'电机' from dual union all
select 'b' ,5 ,2 ,'压缩机' from dual union all
select 'b' ,6 ,1 ,'电机' from dual )
select product,
sum(case when bomid =1 or bomid=5 then bomid else 0 end ) 压缩机1编码,
sum(case when bomid =1 or bomid=5 then qnt else 0 end ) qnt ,
sum(case when bomid =2 then bomid else 0 end ) 压缩机2编码,
sum(case when bomid =2 then qnt else 0 end ) 压缩机2数量 ,
sum(case when bomid =3 or bomid=4 then bomid else 0 end )电机1编码,
sum(case when bomid =3 or bomid=4 then qnt else 0 end ) 电机1数量,
sum(case when bomid =6 then bomid else 0 end ) 电机2编码,
sum(case when bomid =6 then qnt else 0 end ) 电机2数量
from tb
group by product