hive获取这周五到下周四的区间,周一到周日的区间

-- 获取每个日期所在周期的开始和结束时间
SELECT
    created_date AS date_in_period,
    CASE
        WHEN date_format(created_date, 'u') < 5 THEN date_sub(created_date, cast(date_format(created_date, 'u') AS INT) + 2)
        ELSE date_sub(created_date, cast(date_format(created_date, 'u') AS INT) - 5)
    END AS period_start,
    CASE
        WHEN date_format(created_date, 'u') < 5 THEN date_add(created_date, 4 - cast(date_format(created_date, 'u') AS INT))
        ELSE date_add(created_date, 11 - cast(date_format(created_date, 'u') AS INT))
    END AS period_end,
    date_format(created_date, 'u') actual_week
FROM ods_ticket_full
where dt = '2024-05-10';

获取周一到周日的星期区间

with t1 as (
    select sp_no,
           sp_name,
           item,
           applyer,
           date_format(from_utc_timestamp(apply_time * 1000, 'America/Los_Angeles'),'yyyy-MM-dd HH:mm:ss')   apply_time_pst,
           date_format(from_utc_timestamp(apply_time * 1000, 'Asia/Shanghai'), 'yyyy-MM-dd HH:mm:ss') apply_time_cst,
           department_name,
           expect_install_time,
           approver,
           date_format(from_utc_timestamp(approver_time * 1000, 'Asia/Shanghai'), 'yyyy-MM-dd HH:mm:ss') approver_time_cst
    from ods_installation_timeout_full
    where dt = '2024-05-13'
)
-- insert overwrite table ads_installation_timeout
select sp_no,
       sp_name,
       item,
       applyer,
       apply_time_pst,
       apply_time_cst,
       department_name,
       expect_install_time,
       approver,
       approver_time_cst,
       concat(year(date_sub(next_day(approver_time_cst, 'MO'), 4)), '-', if(weekofyear(approver_time_cst)<10,concat('0',weekofyear(approver_time_cst)),weekofyear(approver_time_cst)))  actual_week,
        -- 获取每个日期所在周期的开始和结束时间
       -- 对于输入的日期,start_of_week将调整到所在周的周一,end_of_week将调整到所在周的周日。
       date_sub(approver_time_cst, cast(date_format(approver_time_cst, 'u') AS INT) - 1) AS start_date, -- 当日期为周一时,返回自身;否则返回本周周一
       date_add(approver_time_cst, 7 - cast(date_format(approver_time_cst, 'u') AS INT)) AS end_date,-- 当日期为周日时,返回自身;否则返回本周周日
       concat(date_format(approver_time_cst,'yyyy-MM'),'-01') actual_month,
       concat(year(approver_time_cst),'-',quarter(approver_time_cst)) actual_quarter
from t1
where datediff(expect_install_time,approver_time_cst)<

相关推荐

  1. Vue生命周期

    2024-05-15 15:24:12       63 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-15 15:24:12       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-15 15:24:12       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-15 15:24:12       82 阅读
  4. Python语言-面向对象

    2024-05-15 15:24:12       91 阅读

热门阅读

  1. Intel RealSense D455深度相机驱动安装与运行

    2024-05-15 15:24:12       37 阅读
  2. 配置多个SSH密钥以访问不同平台(GitHub、Gitee)

    2024-05-15 15:24:12       36 阅读
  3. 用wordpress建外贸独立站的是主流的外贸建站方式

    2024-05-15 15:24:12       35 阅读
  4. HIVE调优

    2024-05-15 15:24:12       26 阅读
  5. AFM 433

    2024-05-15 15:24:12       33 阅读
  6. C语言-STM32:介绍PWM,并使用PWM实现呼吸灯

    2024-05-15 15:24:12       34 阅读
  7. 你眼中的IT行业现状与未来趋势

    2024-05-15 15:24:12       29 阅读
  8. Element-ui el-table组件单选/多选/跨页勾选讲解

    2024-05-15 15:24:12       34 阅读
  9. js判断是否PC端

    2024-05-15 15:24:12       35 阅读
  10. kafka管理工具 kafka-ui 的 k8s 部署

    2024-05-15 15:24:12       24 阅读
  11. mac中launchctl使用教程

    2024-05-15 15:24:12       29 阅读
  12. 使用IDEA搭建MyBatis环境

    2024-05-15 15:24:12       29 阅读
  13. 大模型日报2024-05-14

    2024-05-15 15:24:12       32 阅读