【发布时间】:2020-02-06 14:50:59
【问题描述】:
早上, 标题说明了一切。我一生都无法弄清楚如何在 HQL 中获取当月(或上月等)的第一个工作日。
因此,如果要评估今天的日期,它应该返回 2/3/2020 作为日期,因为 3 号是本月的第一个工作日。
我已经尝试用 case 语句来评估当月的第一天,如果是星期六,加 2 天,星期天,加 1,但它不起作用,我收到以下错误:错误:准备错误:org.apache.hive.service.cli.HiveSQLException:编译语句时出错:FAILED:ParseException 行 1:452 无关输入 ',' 期望 KW_THEN 靠近 ''line 1:626 无关输入 ',' 期望 KW_THEN 靠近 ''
case when date_format(date_add(current_date, 1 - day(current_date)),'u')=6, then to_date(mydate) = date_add(date_add(current_date, 1 - day(current_date)+2))
when date_format(date_add(current_date, 1 - day(current_date)),'u')=7, then to_date(mydate) = date_add(date_add(current_date, 1 - day(current_date)+1))
else to_date(mydate) = date_add(date_add(current_date, 1 - day(current_date))) end
请帮忙!
@Vamsi 普拉巴拉
我试过了,但是我收到的结果是 1。我需要返回一个日期,特别是本月的 2020 年 2 月 3 日。
case when date_format(date_add(current_date, 1 - day(current_date)),'u')> 5 then
to_date(mydate)= to_date(date_add(date_add(current_date, 1 - day(current_date)),8-cast(date_format(date_add(current_date, 1 - day(current_date)),'u') as int)%8))
else to_date(mydate) = date_add(current_date, 1 - day(current_date)) end
【问题讨论】:
-
上一篇文章有帮助吗? stackoverflow.com/questions/22982904/…
-
我已经能够通过以下内容确定它是星期几; when date_format(current_date,'u')=1 (1= monday, 2 = Tuesday etc.) 但是我不知道如何结合它来确定这是否是本月的第一个工作日。
-
因此,如果要评估今天的日期,它应该返回 2/3/2020 作为日期,因为 3 号是本月的第一个工作日。这有意义吗?
-
啊现在我明白了。对不起,我的错。不幸的是,我不知道如何在 Hive 中确定这一点。