报错信息1: Only SubQuery expressions that are top level conjuncts are allowed
select
distinct investortype,
fi_type.investortype
from
odm.odm_cf_investor_i_d fi_type
where
dt = (
select
max(dt)
from
odm.odm_cf_investor_i_d
where
dt = fi_type.dt
)
报错信息2: Invalid column reference 'xxx'
select
distinct investortype,
fi_type.investortype
from
odm.odm_cf_investor_i_d fi_type
解决方法:
fi_type.investortype as type -- 重命名即可
原因分析:
Tez引擎在查询同名字段时,会从第二个同名字段开始自动重命名,即添加后缀:_1、_2 ……
自我猜测是当添加了distinct后就不会自动重命名了,因此导致了错误
但是上面两个报错信息不同,第一个提示的是dt出错,第二个提示的是字段出错
在Presto引擎中这两个SQL都可以正常执行