hive星期函数

01、取当前周的周一:select
    date_add(next_day(current_date,
    'MO'),
    -7)

当前日期(2021-07-27)返回结果:hive星期函数_第1张图片

02、整理日期格式:取当前日期年月:

select
    date_format(current_date,
    'yyyy-MM');

返回结果:hive星期函数_第2张图片

03、取当月最后一天:

select
    last_day(current_date)

返回结果:hive星期函数_第3张图片

04、 年度第几周函数(周一至周日,新年第一周划分以超过4天的那周所在年为准):select
    weekofyear(current_date)

返回结果:hive星期函数_第4张图片

05、取周四至周三的周期数据:

select weekofyear(date_sub('2021-07-28',3))

减3天则为周一至周日,原统计日志为周四至周三,满足需求。

 06、取年&周数据:

select
    year(date_sub(next_day(current_date,
    'MO'),
    4))*100+weekofyear(current_date) deal_week

你可能感兴趣的:(HQL,hive,hadoop,数据仓库)