select sum(FQty)as PR1 from PORequest a1 inner join PORequestEntry a2 on a1.FInterID=a2.FInterID where FStatus>0 and FCancellation=0
group by FItemID 采购申请单的数量
select sum(FQty)as PR2 from POOrder a3 inner join POOrderEntry a4 on a3.FInterID=a4.FInterID
where FCancellation=0 and FSourceTranType=70 group by FItemID
下推的数量
试下下面这个
select A.PR1-B.PR2 from
(select sum(FQty)as PR1 from PORequest a1 inner join PORequestEntry a2 on a1.FInterID=a2.FInterID where FStatus>0 and FCancellation=0
group by FItemID) as A
OUTER APPLY(select sum(FQty)as PR2 from POOrder a3 inner join POOrderEntry a4 on a3.FInterID=a4.FInterID
where FCancellation=0 and FSourceTranType=70 group by FItemID) as B
SELECT FItemID,PR1-PR2 FROM (
select FItemID,sum(FQty)as PR1 from PORequest a1 inner join PORequestEntry a2 on a1.FInterID=a2.FInterID where FStatus>0 and FCancellation=0
group by FItemID)A,
(select FItemID,sum(FQty)as PR2 from POOrder a3 inner join POOrderEntry a4 on a3.FInterID=a4.FInterID
where FCancellation=0 and FSourceTranType=70 group by FItemID)B
WHERE A.FItemID=B.FItemID