假设我有一个带有四个双列A,B,C和D的表(my_table)。我想创建一个新表,它使用现有表中的派生数据:
create table my_new_table as select A, B, C, D, A / (C + D), B / (C + D) from my_table;
有没有办法定义一个局部变量(例如my_var = C + D),我可以在select语句中声明然后在整行中使用,即
create table my_new_table as select A, B, C, D, A / my_var, B / my_var from my_table;
只是想知道这在Hive中是否可行。
答案 0 :(得分:1)
是的,这是可行的,这是一个如何做的例子。
set my_var = C+D;
create table my_new_table as
select A, B, C, D, A / ${hiveconf:my_var}, B / ${hiveconf:my_var} from my_table;