老实说,我不知道如何简单地在标题行中描述问题而不是展示示例。
我有一个包含两列的配置单元表:ID 和日期
ID Date
31 01-01-2017
31 01-02-2017
31 01-03-2017
123 01-01-2017
123 01-01-2017
...
在这个表中,我想包括另一列是小时,如下所示
ID Date Hour
31 01-01-2017 00
31 01-01-2017 01
31 01-01-2017 02
31 01-01-2017 03
31 01-01-2017 04
...
31 01-01-2017 23
31 01-02-2017 00
31 01-02-2017 01
...
基本上,对于每一行,我想添加一个小时值从 00 到 23 的列。 这可以使用 hive 来实现吗? 非常感谢。
最佳答案
您可以创建一个临时表,其中包含从 0 到 23 的条目,并与您拥有的表进行交叉连接。或者,您可以利用 CTE 函数创建一个包含从 0 到 23 的条目的 CTE 表,然后对其进行交叉连接。
一个例子:
with temp as (
select 0 hour union all
select 1 hour union all
select 2 hour union all
select 3 hour union all
select 4 hour union all
select 5 hour union all
select 6 hour union all
select 7 hour union all
select 8 hour union all
select 9 hour union all
select 10 hour union all
select 11 hour union all
select 12 hour union all
select 13 hour union all
select 14 hour union all
select 15 hour union all
select 16 hour union all
select 17 hour union all
select 18 hour union all
select 19 hour union all
select 20 hour union all
select 21 hour union all
select 22 hour union all
select 23 hour
)
select * from table join temp
您还可以将结果插入表中以持久化结果。希望对你有帮助
关于hadoop - 配置单元 - 为不同的列值插入行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48240451/