HIVE 計算指定日期本週的第一天和最後一天

 

 1 -- 計算指定日期本週的第一天和最後一天
 2 select
 3      day
 4     ,dayofweek(day)                                                                    as dw1  5     ,date_add(day,1 - dayofweek(day))                                                  as Su_s -- 週日_start
 6     ,date_add(day,7 - dayofweek(day))                                                  as Sa_e -- 週六_end
 7     ,case when dayofweek(day) = 1 then 7 else dayofweek(day) - 1 end                   as dw2  8     ,date_add(day,1 - case when dayofweek(day) = 1 then 7 else dayofweek(day) - 1 end) as Mo_s -- 週一_start
 9     ,date_add(day,7 - case when dayofweek(day) = 1 then 7 else dayofweek(day) - 1 end) as Su_e -- 週日_end
10 from ( 11     select '2018-07-01' as day union all
12     select '2018-07-02' as day union all
13     select '2018-07-03' as day union all
14     select '2018-07-04' as day union all
15     select '2018-07-05' as day union all
16     select '2018-07-06' as day union all
17     select '2018-07-07' as day union all
18     select '2018-07-08' as day union all
19     select '2018-07-09' as day union all
20     select '2018-07-10' as day union all
21     select '2018-07-11' as day union all
22     select '2018-07-12' as day union all
23     select '2018-07-13' as day union all
24     select '2018-07-14' as day union all
25     select '2018-07-15' as day union all
26     select '2018-07-16' as day union all
27     select '2018-07-17' as day union all
28     select '2018-07-18' as day union all
29     select '2018-07-19' as day union all
30     select '2018-07-20' as day union all
31     select '2018-07-21' as day union all
32     select '2018-07-22' as day
33 ) t1 34 ;
相關文章
相關標籤/搜索