zoukankan      html  css  js  c++  java
  • 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 ;
  • 相关阅读:
    Python常用转换函数
    Python随机数
    sublime text的pylinter插件设置pylint_rc后提示错误
    使用Pydoc生成文档
    字符编码笔记:ASCII,Unicode和UTF-8
    Windows编程MessageBox函数
    魔方阵算法及C语言实现
    iOS通讯录整合,兼容iOS789写法,附demo
    谈谈iOS app的线上性能监测
    ReactiveCocoa代码实践之-更多思考
  • 原文地址:https://www.cnblogs.com/chenzechao/p/9336764.html
Copyright © 2011-2022 走看看