首页 新闻 会员 周边

请问这两张表怎么左连接 在线等

0
[已解决问题] 解决于 2015-08-10 15:13

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

龙o魂的主页 龙o魂 | 初学一级 | 园豆:198
提问于:2015-07-30 16:32
< >
分享
最佳答案
0

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 

奖励园豆:5
山水中华 | 菜鸟二级 |园豆:255 | 2015-08-01 12:09

这不能运行  语法错误

龙o魂 | 园豆:198 (初学一级) | 2015-08-05 09:32

@龙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

再试试,分组那里少了一个字段

山水中华 | 园豆:255 (菜鸟二级) | 2015-08-06 10:47
其他回答(1)
0

把上下两个查询先各自包成一个表 然后左连接就可以

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

at小怪兽 | 园豆:760 (小虾三级) | 2015-07-30 16:50

这不能运行  语法错误

支持(0) 反对(0) 龙o魂 | 园豆:198 (初学一级) | 2015-08-05 09:32

@龙o魂: 你具体再说一下 你的问题

支持(0) 反对(0) at小怪兽 | 园豆:760 (小虾三级) | 2015-08-05 09:42
支持(0) 反对(0) 龙o魂 | 园豆:198 (初学一级) | 2015-08-05 10:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册