hive函数dayofweek的奇怪用法

hive函数dayofweek的奇怪用法

1.单独使用

select `dayofweek`('2023-07-03'); 周一 2
select `dayofweek`('2023-07-04'); 周二 3
select `dayofweek`('2023-07-05'); 周三 4
select `dayofweek`('2023-07-06'); 周四 5
select `dayofweek`('2023-07-07'); 周五 6
select `dayofweek`('2023-07-08'); 周六 7
select `dayofweek`('2023-07-09'); 周日 1

发现是1-星期天;2-星期一;3-星期二;以此类推

2.如果是使用的是表的时间列

select
    cur_date,
    `dayofweek`(cur_date)
from (
         select date_format(cur_date, 'yyyy-MM-dd') cur_date
         from ods_cn_attendance_day_print_full
         where dt = '2023-07-05'
         group by date_format(cur_date, 'yyyy-MM-dd')
     )t1
order by cur_date desc
limit 10;

在这里插入图片描述
得到的结果是周一是1,周二是2,周三3,…周日是7

所以这种结果很奇怪,我后面又试了几次,发现hive的dayofweek得到的结果还会变化,所以最保险的做法就是:
再创建一张表,然后将dayofweek加入该表中

重新建表

drop table if exists hr_cn.dwd_employee_daily_punch_record_detail_cross_day2;
create external table IF NOT EXISTS hr_cn.dwd_employee_daily_punch_record_detail_cross_day2
(
    staff_id string comment '员工id',
    user_name string comment '员工姓名',
    finger_print_number             string comment '员工指纹',
    group_name string comment '员工所属组别',
    leader_name string comment '组长',
    actual_date              string comment '打卡日期',
    cur_week int comment '打卡日期所属的星期',
    Actual_In                string comment '上班签入时间',
    Actual_Out               string comment '下班签出时间',
    Acutal_In_BF             string comment '早餐签入时间',
    Acutal_Out_BF            string comment '早餐签出时间',
    Acutal_In_Lunch          string comment '午餐签入时间',
    Acutal_Out_Lunch         string comment '午餐签出时间',
    Acutal_In_Dinner string comment '宵夜签入时间',
    Acutal_Out_Dinner        string comment '宵夜签出时间',
    Acutal_In_Work_Overtime  string comment '加班签入时间',
    Acutal_Out_Work_Overtime string comment '加班签出时间',
    Mobile_Officing_In       string comment '移动办公签入时间',
    Mobile_Officing_Out      string comment '移动办公签出',
    department string comment '部门',
    position_status int comment '在职状态,1代表在职,0代表离职',
    punch_type int comment '班次类型 1-日班;2-夜班',
    title string comment '班次名'
) comment '员工日班每天打卡记录表'
partitioned by (dt string)
row format delimited fields terminated by '\001'
NULL DEFINED AS ''
stored as orc
LOCATION '/warehouse/hr_cn/dwd/dwd_employee_daily_punch_record_detail_cross_day2';
insert overwrite table dwd_employee_daily_punch_record_detail_cross_day2 partition (dt='2023-07-06')
select staff_id,
       user_name,
       finger_print_number,
       group_name,
       leader_name,
       actual_date,
       dayofweek(actual_date) cur_week,
       Actual_In,
       Actual_Out,
       Acutal_In_BF,
       Acutal_Out_BF,
       Acutal_In_Lunch,
       Acutal_Out_Lunch,
       Acutal_In_Dinner,
       Acutal_Out_Dinner,
       Acutal_In_Work_Overtime,
       Acutal_Out_Work_Overtime,
       Mobile_Officing_In,
       Mobile_Officing_Out,
       department,
       position_status,
       punch_type,
       title
from dwd_employee_daily_punch_record_detail_cross_day
where dt = '2023-07-06';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_37759590

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值