hive 高效的SQL派生值插入和查找

2fjabf4q  于 6个月前  发布在  Hive
关注(0)|答案(1)|浏览(81)

如何有效地对派生变量执行where。例如,我正在计算event_date以插入到表中。但我想在where子句中使用我在此阶段计算的变量。是否有一种有效的方法来执行此操作,而不是再次计算它?

insert into table {table} 
(
  event_header_event_id 
, event_date 
) 
select 
  cs.event_header_event_id as event_header_event_id
, try_cast(concat(cs.year, "-", cs.month, "-", cs.day) as string) as event_date
from source_table cs where event_date  >= date_add(current_date(), -{daysback} );

字符串

eqoofvh9

eqoofvh91#

你可以在数据砖中使用date_sub函数。下面是一个例子:

insert into table {table} 
(
  event_header_event_id 
, event_date 
) 
select cs.event_header_event_id as event_header_event_id,
try_cast(concat(cs.year, "-", cs.month, "-", cs.day) as string) as event_date
FROM events
WHERE event_date > date_sub(current_date(), daysback);

字符串

相关问题