我有效T-SQL查询:6 b0 H( @. ^! q
select t1.* ,case when s1.period is not null then 'Y' else 'N' end as flag_cur ,case when s2.period is not null then 'Y' else 'N' end as flag_prev ,s1.cutoff_date as cutoff_date_cur ,s1.cutoff_dtkey as cutoff_dtkey_cur s2.cutoff_date as cutoff_date_prev ,s2.cutoff_dtkey as cutoff_dtkey_prev into #tmp_leads2from #tmp_leads t1left join #param s1 on s1.period = '(a) Current' and s1.begin_date 我试图重新配置它Hive(v0.13)如下所示:: s3 v2 F. _: Q* o/ U
create table tmp_leads2 as select t1.* ,case when s1.period is not null then 'Y' else 'N' end as flag_cur ,case when s2.period is not null then 'Y' else 'N' end as flag_prev ,s1.cutoff_date as cutoff_date_cur ,s1.cutoff_dtkey as cutoff_dtkey_cur s2.cutoff_date as cutoff_date_prev ,s2.cutoff_dtkey as cutoff_dtkey_prev from tmp_leads t1left join param s1 on s1.period = '(a) Current' and s1.begin_date 但我犯了一个错误: : h* w7 x. R' c2 s q# ZError occurred executing hive query: OK FAILED: SemanticException [Error 10017]: Line 8:53 Both left and right aliases encountered in JOIN 'CreatedDate'我看到了它讨论的字段,但我不确定如何在保持相同查询结果的同时重写字段。% y8 Z, N: r' P* b5 Q# n$ ]
4 G3 N+ h: g( ] 解决方案: y) M' q+ y" Y- {4 d
问题来自joins不等式条件。这带来了问题。以下内容可能足以满足您的目的:$ W5 R+ _* P0 ?* B6 G( U/ T
create table tmp_leads2 as select t1.*, (case when s1.period is not null then 'Y' else 'N' end) as flag_cur, (case when s2.period is not null then 'Y' else 'N' end) as flag_prev, s1.cutoff_date as cutoff_date_cur,s1.cutoff_dtkey as cutoff_dtkey_cur s2.cutoff_date as cutoff_date_prev,s2.cutoff_dtkey as cutoff_dtkey_prev from tmp_leads t1 left join param s1 on s1.period = '(a) Current' left join param s2 on s2.period = '(b) Previous' where (s1.begin_date is null or s1.begin_date 这并不完全等效。假设表中有参数,所有日期都在表中。这可能是一个合理的假设。如果没有,则需要更复杂的查询。