zoukankan      html  css  js  c++  java
  • Hive SQL 常用日期

    Hive SQL 常用日期

    原文地址:Hive SQL常用日期函数

    Hive SQL 常用日期

    注意: MM DD MO TU等要大写

    已知日期 要求日期 语句 结果
    本周任意一天 本周一 select date_sub(next_day('2016-11-29','MO'),7) ; 2016-11-28
    本周任意一天 上周一 select date_sub(next_day('2016-11-29','MO'),14); 2016-11-21
    本周任意一天 本周二 select date_sub(next_day('2016-11-29','MO'),6) 2016-11-29
    本周任意一天 上周二 select date_sub(next_day('2016-11-29','MO'),13) ; 2016-11-22
    本周任意一天 上周末 select date_sub(next_day('2016-11-29','MO'),8) ; 2016-11-27
    本月任意一天 上月末 select date_sub(trunc('2016-11-02','MM'),1); 2016-10-31
    本月任意一天 上月初 select trunc(add_months('2016-11-02',-1),'MM') 2016-10-01
    本月任意一天 本月初 select trunc('2016-11-02','MM') 2016-11-01
    本月任意一天 上上月26 select date_add(add_months(trunc('2016-11-02','MM'),-2),25) ; 2016-09-26
    本月任意一天 上月26 select date_add(add_months(trunc('2016-11-02','MM'),-1),25) ; 2016-10-26
    当前时间戳 select current_timestamp() ; 2016-11-30 15:18:06.276
    当前时间 select current_date() ; 2016-11-30
    本季度任意一天 上季度初 case quarter('2016-05-23')
      when 1 then concat(year('2016-05-23')-1,'-10-01')
      when 2 then concat(year('2016-05-23'),'-01-01')
      when 3 then concat(year('2016-05-23'),'-04-01')
      when 4 then concat(year('2016-05-23'),'-07-01')
    end
    或 add_months(concat(year('2017-02-23'),'-',substr(concat('0',quarter('2017-02-23')*3+1),-2),'-01'),-6)
    本季度任意一天 本季度初 case quarter('2016-05-23')
       when 1 then concat(year('2016-05-23'),'-01-01')
       when 2 then concat(year('2016-05-23'),'-04-01')
       when 3 then concat(year('2016-05-23'),'-07-01')
       when 4 then concat(year('2016-05-23'),'-10-01')
    end

    add_months(concat(year('2017-02-23'),'-',substr(concat('0',quarter('2017-02-23')*3+1),-2),'-01'),-3)
  • 相关阅读:
    PLC衔接新方式UcAsp.Opc
    dev barmanager 中的 add按钮出不来,无法创建菜单的问题解决
    一个或多个页边距被设置到也可打印的页面范围之外,处理方式
    bar设置全背景色
    PHP计算两个字符的相似程度similar_text
    PHP中双冒号::的用法
    百度站内搜索应该注意哪些方面?
    快给你的网站添加微信公众号吧!
    实例讲解网站前台界面开发流程
    百度富文本编辑器UEditor安装配置全过程
  • 原文地址:https://www.cnblogs.com/boothsun/p/7232174.html
Copyright © 2011-2022 走看看