Hive自动生成数字和日期

生辰数字
select posexplode(split(repeat("o", datediff("2022-12-31", "2022-12-16")), "o"))

生成日期

with dates as (
    select date_add("2012-01-01", a.pos) as d
    from (
             select posexplode(split(repeat("o", datediff("2022-12-31", "2012-01-01")), "o"))) a
)
select d                                             as date_id
     , weekofyear(d)                                 as week_id
     , if(`dayofweek`(d) = 1, 7, `dayofweek`(d) - 1) as week_day
     , dayofmonth(d)                                 as day
     , month(d)                                      as month
     , quarter(d)                                    as quarter
     , year(d)                                       as year
from dates
order by d;

 

posted @ 2023-01-05 16:10  Wind_LPH  阅读(377)  评论(0编辑  收藏  举报