有关左链接与子查询的疑惑(求助)
做项目忙了一天,头昏脑胀,求助下大家帮忙看下两段SQL
Oracle 10G 版本
第一段
select ebpoE.zbthnr as zbthnr1,ebpoE.Zqgdh,
o.zbthnr2,
ebpoE.ebeln,
ebpoE.ebelp from t_sap_eban ebpoE
left join (
select eban.banfn,eban.bnfpo,decode(nvl(ekpo.ebeln_pre, ''),
'',
(select eb.zbthnr
from t_sap_eban eb
where eb.ebeln || '-' || eb.ebelp =
ekpo.konnr || '-' || ekpo.ktpnr
and
eb.loekz is null and rownum =1),
(select eb.zbthnr
from t_sap_eban eb
where eb.ebeln || '-' || eb.ebelp =
ekpo.ebeln_pre || '-' || ekpo.ebelp_pre
and
eb.loekz is null and rownum =1)) as zbthnr2
from t_sap_eban eban, t_sap_ekpo ekpo
WHERE nvl(eban.ebeln,'') || '-' ||nvl(eban.ebelp,'') =
ekpo.ebeln || '-' || ekpo.ebelp
) o
on o.banfn||'-'||o.bnfpo = ebpoE.banfn||'-'||ebpoE.bnfpo
where ebpoE.Ebeln = '4700038450'
select ebpoE.zbthnr as zbthnr1,ebpoE.Zqgdh,
(select decode(nvl(ekpo.ebeln_pre, ''),
'',
(select nvl(eb.zbthnr, '')
from t_sap_eban eb
where eb.ebeln || '-' || eb.ebelp =
ekpo.konnr || '-' || ekpo.ktpnr
and
eb.loekz is null and rownum =1),
(select nvl(eb.zbthnr, '')
from t_sap_eban eb
where eb.ebeln || '-' || eb.ebelp =
ekpo.ebeln_pre || '-' || ekpo.ebelp_pre
and
eb.loekz is null and rownum =1)) as zbthnr2
from t_sap_eban eban, t_sap_ekpo ekpo
WHERE eban.ebeln || '-' || eban.ebelp =
ekpo.ebeln || '-' || ekpo.ebelp
and eban.banfn|| '-' ||eban.bnfpo = ebpoE.banfn|| '-' ||ebpoE.bnfpo)
as zbthnr2,
ebpoE.ebeln,
ebpoE.ebelp
from t_sap_eban ebpoE where nvl(ebpoE.Ebeln,'') = '4700038450'