我有效T-SQL查询: 2 S$ }1 O! f% x/ dselect 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)如下所示:1 q/ I; ^3 B3 H$ O4 ?
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 但我犯了一个错误:' I; {; C* [. j+ a8 x2 t
Error occurred executing hive query: OK FAILED: SemanticException [Error 10017]: Line 8:53 Both left and right aliases encountered in JOIN 'CreatedDate'我看到了它讨论的字段,但我不确定如何在保持相同查询结果的同时重写字段。" T$ W- Y3 z& ]& P( Q% [ b
( e& b/ P+ i( t2 {$ v. A U* v 解决方案: : ^/ V9 c8 O' G 问题来自joins不等式条件。这带来了问题。以下内容可能足以满足您的目的:1 p- N; }- `( q& ~' t1 H1 r
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 这并不完全等效。假设表中有参数,所有日期都在表中。这可能是一个合理的假设。如果没有,则需要更复杂的查询。