22,207
社区成员
发帖
与我相关
我的任务
分享
select a.mater_code,a.pdwet,c.jieguo as gxwet,a.mtwet,a.mtgmawet,b.item_order from
(select a.mater_code,sum(case when TAG='A' then wet else 0 end) as pdwet,
sum(case when TAG='包根' then wet else 0 end) as gxwet,
sum(case when TAG='GC' then wet else 0 end) AS mtwet,
sum(case when TAG='GMA' then wet else 0 end) AS mtGMAwet
from
(select b.mater_code,sum(round(a.wet*b.len_xs,2)) as wet,tag from #temppd a left join #tempbom b on a.item_code=b.item_code
where b.class_code=2 and b.mater_code is not null group by b.mater_code,a.tag
union all
select b.mater_code,sum((a.wet*b.len_xs/100)) as wet, '包根' AS tag from #temppd_gx a left join tempbom b on a.item_code=b.item_code
where b.class_code=1 and b.mater_code is not null group by b.mater_code
union all
select item_code as mater_code,wet,packno AS tag from #temppd_mt
) a group by a.mater_code,a.tag
)a left join fourk.dbo.item b on a.mater_code=b.item_code
order by item_order
select *
from a left join b on a.id=b.id
left join c on a.id=c.id
left join d on b.id=d.id