gpt4 book ai didi

sql - Teradata 错误 3782 联接表的搜索条件中的列引用不正确

转载 作者:行者123 更新时间:2023-12-04 02:19:24 25 4
gpt4 key购买 nike

我对我继承的一些 sql 进行了一些更改(在下面突出显示),并且我得到了

Error 3782 Improper column reference in the search condition of a joined table



我不知道为什么我会收到这条消息。任何帮助将不胜感激。
with dqry_cc (mop_cd, mop_desc, group_branch_id, ecr_tmz_name, stn_stn_id ,  stn_id, grp_brn_id  ) as

(select
a.mop_cd ,
a.mop_desc,
so.group_branch_id ,
t.ecr_tmz_name,
so.stn_stn_id,
s.stn_id ,
s.grp_brn_id

from
rfs.stn_ops_hierarchies so,
rfs.mthd_of_pymts a,
rfs.stns s,
rfs.tmzs_map t

where s.stn_id = so.stn_stn_id
and a.mpt_mop_type_code = 'CC'
and s.TMZ = t.TMZS_TMZ
and so.group_id = '01'
and so.region_cd = 'RGN_stl_99'
and so.group_branch_id ='0101')

select *

from

(select
cc.group_branch_id as GpBr,
cc.mop_desc as Descr,
cast(SYSLIB.ERAC_GMT_TO_LCL(ph.pymt_dt, cc.ecr_tmz_name) AS timestamp(6)) as LocalPaydate,
cast(SYSLIB.ERAC_GMT_TO_LCL(ph.pymt_dt, cc.ecr_tmz_name) as date) as ph_pymt_dt,
dr.dvr_srnm as DriverFName,
dr.dvr_frst_name as DriverLName,
ph.name as HolderName,
pd.ticket_no as ECARS2,

cast( case when rb.ecr_lgcy_resv_nbr is null then
case when substr(pd.ticket_no,1,1) = 'D' then
'D'||substr(pd.ticket_no, 2,6)
else
null
end
else 'D'||rb.ecr_lgcy_resv_nbr
end as CHAR(7)) as ECARS1,

rb.rnt_agr_nbr as RntAgrNo,

case when ph.cr_card_trans_typ_cde='R' then
-1*pd.pymt_amt
else
pd.pymt_amt
end as AMOUNT,

pd.cur_curr_cd as Curr,
ph.CR_CARD_NBR as CardNo,

cast(ph.exp_dt as date format 'mm/yy') as ExpireDate,
cast(0 as decimal(15,3)) as AUTH_AMT,
cast(null as date format 'mm/dd/yyyy') as AuthDate,

ph.auth_nbr as AuthNo,

cast(null as char(2)) as Swipe,
cast(null as varchar(60)) as PType,

**pft.Settlement,
pft.First_Six**

from
dqry_cc cc,
rfs_rv.pre_applied_pymts_hdr ph,
rfs_rv.pre_applied_pymts_det pd

left outer join
(select
ra.rnt_agr_nbr,
ra.ecr_ticket_no,
ra.ecre_rent_cntrct_nbr,
ra.ecr_lgcy_resv_nbr,
cc.grp_brn_id --

from
rfs_rv.rnt_agrs ra,
dqry_cc cc

where ra.sta_stn_id_orig_co = cc.stn_id QUALIFY ROW_NUMBER() OVER(PARTITION BY ra.rnt_agr_nbr ORDER BY ra.rnt_agr_nbr) = 1
) rb
on pd.ticket_no = rb.ecr_ticket_no

left outer join
(select
dvr.dvr_srnm,
dvr.dvr_frst_name,
dvr.rdy_rnt_agr_nbr

from rfs_rv.dvr_rras dvr

where dvr.main_dvr_flg = 'MR'
) dr
on rb.rnt_agr_nbr = dr.rdy_rnt_agr_nbr

**left outer join
(select
ft.paymt_mdia_proc_sys_cde as Settlement,
ft.prim_acct_frst_six_dgt_nbr as First_Six,
ft.fin_tran_ref_id

from paymt.fin_tran ft) pft
on pft.fin_tran_ref_id = cast(ph.paph_fin_trans_ref_id as decimal(19,0))**

where ph.pymt_stn_id = cc.stn_stn_id
and ph.mop_mop_cd = cc.mop_cd
and ph.pymt_id = pd.pap_pymt_id
and ph_pymt_dt = 8/5/2015

) z

最佳答案

您混合了新旧风格的连接语法。如果您遵循以下简单规则,您的问题将永远不会存在:永远不要使用逗号 FROM条款。始终使用显式 JOIN句法。

问题是逗号运算符周围的范围。虽然它在功能上等同于 CROSS JOIN ,第一部分不是第二部分的已知别名。

如果您修复 FROM删除所有逗号,您的问题将得到解决,即使您只将逗号更改为 CROSS JOIN .但是,我建议使用正确的 JOIN .

关于sql - Teradata 错误 3782 联接表的搜索条件中的列引用不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32017726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com