有些物品以多个单位生产。要找到以不同单位生产的商品并找到单位名称?

时间:2020-07-17 05:15:54

标签: sql

with UNIT6 as(
select t0.ItemCode,t0.OcrCode
,sum(t0.PlannedQty) 'PlannedQty'
from owor t0 where t0.CreateDate>='2020-07-01 00:00:00.000'
and t0.OcrCode='UNIT6'
group by t0.ItemCode ,t0.OcrCode
),
UNIT7 as(
select t0.ItemCode,t0.OcrCode
,sum(t0.PlannedQty) 'PlannedQty'
from owor t0 where t0.CreateDate>='2020-07-01 00:00:00.000'
and t0.OcrCode='UNIT7'
group by t0.ItemCode,t0.OcrCode
)
select (select itemname from oitm o1 where o1.itemcode=t1.ItemCode)'itemname' ,* from UNIT6 t1 
inner join UNIT7 t2 on t1.ItemCode=t2.ItemCode

这是2个单位的示例,我想要多个单位的结果

enter image description here

0 个答案:

没有答案