select FQty as f1,a2.FItemID from PORequest a1 inner join PORequestEntry a2 on a1.FInterID=a2.FInterID
where FStatus>0 and FCancellation=0 group by a2.FItemID
select FQty as f2,a4.FItemID from POOrder a3 inner join POOrderEntry a4 on a3.FInterID=a4.FInterID
where FCancellation=0 and FSourceTranType=70
select t1.f1,t1.FItemID ,t2.f2 from
(select FQty as f1,a2.FItemID from PORequest a1 inner join PORequestEntry a2 on a1.FInterID=a2.FInterID
where FStatus>0 and FCancellation=0 group by a2.FItemID ) as t1
left join ( select FQty as f2,a4.FItemID from POOrder a3 inner join POOrderEntry a4 on a3.FInterID=a4.FInterID
where FCancellation=0 and FSourceTranType=70) as t2
on t1.FItemID =t2.FItemID
这不能运行 语法错误
@龙o魂: 少写了一个地方,还有你的FQty,FStatus FCancellation 字段指定不明确,不知道是哪个表、最好表明一下
select t1.f1,t1.FItemID ,t2.f2 from
(select FQty as f1,a2.FItemID from PORequest a1 inner join PORequestEntry a2 on a1.FInterID=a2.FInterID
where FStatus>0 and FCancellation=0 group by a2.FItemID ,FQty ) as t1
left join ( select FQty as f2,a4.FItemID from POOrder a3 inner join POOrderEntry a4 on a3.FInterID=a4.FInterID
where FCancellation=0 and FSourceTranType=70) as t2
on t1.FItemID =t2.FItemID
再试试,分组那里少了一个字段
把上下两个查询先各自包成一个表 然后左连接就可以
with tb1 as(
select FQty as f1,a2.FItemID from PORequest a1 inner join PORequestEntry a2 on a1.FInterID=a2.FInterID
where FStatus>0 and FCancellation=0 group by a2.FItemID
)
with tb2 as(
select FQty as f2,a4.FItemID from POOrder a3 inner join POOrderEntry a4 on a3.FInterID=a4.FInterID
where FCancellation=0 and FSourceTranType=70
)
select * from tb1 a left join tb2 b on a.FItemID = b.FItemID
这不能运行 语法错误
@龙o魂: 你具体再说一下 你的问题