有没有一种方法可以动态地向配置单元中返回的所有记录添加一个常量值?

cmssoen2  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(296)

我想在hivev1.2.1中执行以下查询,其中 field_3 从另一个表中查询。

select user_id, start_date, field_3 as stop_date
from some_table;

对于每个返回的记录 field_3 是一样的。问题是它存储在另一个表中。为了得到这个值,我可以得到如下。

select max(some_field) as stop_date
from another_table;

目前,我已经硬编码了文字。

select user_id, start_date, cast(cast('2017-10-19' as date) as timestamp) as stop_date
from some_table;

但是,这种方法是不可取的,因为适当的值会在一天中发生变化。
任何解决方案都应该考虑是否可以通过配置单元sql上下文插入spark。

f3temu5u

f3temu5u1#

您可以联接另一个表的输出。。

select user_id, start_date, b.field_3 as stop_date FROM 
some_table a,
( select max(some_field) as field_3 
from another_table ) b;

相关问题