如何在HIVE中获得季度开始的日期和时间?

时间:2019-04-09 01:38:46

标签: hive

我需要建立一个日期表,其中包含星期几,每年的某年…… 现在我在执行季度开始日期,结束日期,每个季度的时间和配置单元中的季度数时遇到问题。蜂巢中的任何日期函数都可以做到这一点?

SELECT
        year(FULL_DATE)*10000+month(FULL_DATE)*100+day(FULL_DATE) AS DATE_ID,
        FULL_DATE,
        CASE date_format(FULL_DATE,'u')
                WHEN 1 THEN '2'
                WHEN 2 THEN '3'
                WHEN 3 THEN '4'
                WHEN 4 THEN '5'
                WHEN 5 THEN '6'
                WHEN 6 THEN '7'
                WHEN 7 THEN '1'
        END AS DAY_NUM_IN_WEEK,
        day(FULL_DATE) AS DAY_NUM_IN_MONTH,
        datediff(FULL_DATE,'2009-04-06') + 1 AS DAY_NUM_OVRLL,
        CASE date_format(FULL_DATE,'u')
                WHEN 1 THEN 'Monday'
                WHEN 2 THEN 'Tuesday'
                WHEN 3 THEN 'Wednesday'
                WHEN 4 THEN 'Thursday'
                WHEN 5 THEN 'Friday'
                WHEN 6 THEN 'Saturday'
                WHEN 7 THEN 'Sunday'
        END AS DAY_NAME,
        CASE date_format(FULL_DATE,'u')
                WHEN 1 THEN 'Mon'
                WHEN 2 THEN 'Tues'
                WHEN 3 THEN 'Wed'
                WHEN 4 THEN 'Thu'
                WHEN 5 THEN 'Fri'
                WHEN 6 THEN 'Sat'
                WHEN 7 THEN 'Sun'
        END AS DAY_NAME_ABBR,
        CASE
                WHEN date_format(FULL_DATE,'u') in (1,2,3,4,5) THEN 'weekend(N)'
                WHEN date_format(FULL_DATE,'u') in(6,7) THEN 'Weekday(Y)'
        END AS WEEK_DAY_FLAG,
        NULL AS HLDY_FLAG,
        weekofyear(FULL_DATE) AS WEEK_NUM_IN_YEAR
                --QUARTER_BEGIN_DATE
                --QUARTER_END_DATE
                --TIME_GONE_PER_QUARTER
                --QUARTER_NUM
From
           seq_date

这是我所做的配置单元查询的一部分。 seq_date是一个表,包含从2009-04-06到2029-04-04的日期范围,而FULL_DATE是每个单独的日期。

SELECT
        year(FULL_DATE)*10000+month(FULL_DATE)*100+day(FULL_DATE) AS DATE_ID,
        FULL_DATE,
        CASE date_format(FULL_DATE,'u')
                WHEN 1 THEN '2'
                WHEN 2 THEN '3'
                WHEN 3 THEN '4'
                WHEN 4 THEN '5'
                WHEN 5 THEN '6'
                WHEN 6 THEN '7'
                WHEN 7 THEN '1'
        END AS DAY_NUM_IN_WEEK,
        day(FULL_DATE) AS DAY_NUM_IN_MONTH,
        datediff(FULL_DATE,'2009-04-06') + 1 AS DAY_NUM_OVRLL,
        CASE date_format(FULL_DATE,'u')
                WHEN 1 THEN 'Monday'
                WHEN 2 THEN 'Tuesday'
                WHEN 3 THEN 'Wednesday'
                WHEN 4 THEN 'Thursday'
                WHEN 5 THEN 'Friday'
                WHEN 6 THEN 'Saturday'
                WHEN 7 THEN 'Sunday'
        END AS DAY_NAME,
        CASE date_format(FULL_DATE,'u')
                WHEN 1 THEN 'Mon'
                WHEN 2 THEN 'Tues'
                WHEN 3 THEN 'Wed'
                WHEN 4 THEN 'Thu'
                WHEN 5 THEN 'Fri'
                WHEN 6 THEN 'Sat'
                WHEN 7 THEN 'Sun'
        END AS DAY_NAME_ABBR,
        CASE
                WHEN date_format(FULL_DATE,'u') in (1,2,3,4,5) THEN 'weekend(N)'
                WHEN date_format(FULL_DATE,'u') in(6,7) THEN 'Weekday(Y)'
        END AS WEEK_DAY_FLAG,
        NULL AS HLDY_FLAG,
        weekofyear(FULL_DATE) AS WEEK_NUM_IN_YEAR
                --QUARTER_BEGIN_DATE
                --QUARTER_END_DATE
                --TIME_GONE_PER_QUARTER
                --QUARTER_NUM
From
           seq_date

这是我所做的配置单元查询的一部分。 seq_date是一个表格,其中包含从2009-04-06到2029-04-04的日期范围,而FULL_DATE是每个单独的日期。

0 个答案:

没有答案