如何使用周值配置单元获取月值
How to get month value using week value hive
我想使用周号获取月值。我将周数存储在具有年份值的 table 中
如何使用该周值查询数据库以获取月份值。
我正在使用 hiveQL。
示例:
201801(week) ------->201801(month)
201804(week) ------->201801(month)
假设一周有整整 7 天。提取周数,乘以 7,加到 'year-01-01' 并从结果日期中提取月份,lpad 与 0 从 1 得到 '01' 并与年份连接:
with data_example as(
select stack(3,'201801','201804','201805') as yr_wk
)
select yr_wk, concat(substr(yr_wk, 1,4),
lpad(month(date_add(date(concat(substr(yr_wk, 1,4),'-01-01')),int(substr(yr_wk, 5,2))*7)),2,0)
) yr_mth
from data_example
结果:
yr_wk yr_mth
201801 201801
201804 201801
201805 201802
我想使用周号获取月值。我将周数存储在具有年份值的 table 中 如何使用该周值查询数据库以获取月份值。 我正在使用 hiveQL。
示例:
201801(week) ------->201801(month)
201804(week) ------->201801(month)
假设一周有整整 7 天。提取周数,乘以 7,加到 'year-01-01' 并从结果日期中提取月份,lpad 与 0 从 1 得到 '01' 并与年份连接:
with data_example as(
select stack(3,'201801','201804','201805') as yr_wk
)
select yr_wk, concat(substr(yr_wk, 1,4),
lpad(month(date_add(date(concat(substr(yr_wk, 1,4),'-01-01')),int(substr(yr_wk, 5,2))*7)),2,0)
) yr_mth
from data_example
结果:
yr_wk yr_mth
201801 201801
201804 201801
201805 201802