我有效T-SQL查询: / f# a( [2 [2 h/ Lselect 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)如下所示:* r5 n% q: q) _- c9 s, q
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 但我犯了一个错误: ' |! e. x3 `7 _2 eError occurred executing hive query: OK FAILED: SemanticException [Error 10017]: Line 8:53 Both left and right aliases encountered in JOIN 'CreatedDate'我看到了它讨论的字段,但我不确定如何在保持相同查询结果的同时重写字段。 ; ^8 D: e$ d0 s9 z }& N$ N / r+ h2 Z. r$ s+ o, j( v# Q# h; z9 C 解决方案: $ b2 |2 o$ o- d& P. x
问题来自joins不等式条件。这带来了问题。以下内容可能足以满足您的目的: ! }7 C$ l* w) c3 |/ h* f$ I( |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 这并不完全等效。假设表中有参数,所有日期都在表中。这可能是一个合理的假设。如果没有,则需要更复杂的查询。