Hive 如果日期为mmYYY格式(mm-->;月,YYYY-->;年),如何提取月份部分?

Hive 如果日期为mmYYY格式(mm-->;月,YYYY-->;年),如何提取月份部分?,hive,Hive,我需要从一列中提取“月”,其中日期以mmYYYY(032019)格式存储。我需要提取月列,如果月值为01,02,03(一月、二月、三月),则我需要生成2018-19的新列。如果值为072019,则需要生成2019-20的新值。我尝试下面的代码,但没有得到想要的结果。请有人指导我该如何实现这一点 CASE WHEN month(to_date(from_unixtime(unix_timestamp(dt), 'dd-MM-yyyy'))) IN (01,02,03) THEN

我需要从一列中提取“月”,其中日期以mmYYYY(032019)格式存储。我需要提取月列,如果月值为01,02,03(一月、二月、三月),则我需要生成2018-19的新列。如果值为072019,则需要生成2019-20的新值。我尝试下面的代码,但没有得到想要的结果。请有人指导我该如何实现这一点

    CASE WHEN month(to_date(from_unixtime(unix_timestamp(dt), 'dd-MM-yyyy'))) IN (01,02,03) THEN 
    CONCAT(CONCAT(year(to_date(from_unixtime(unix_timestamp(dt), 'dd-MM-yyyy'))))-1,'-'),
    substr(year(to_date(from_unixtime(unix_timestamp(dt), 'dd-MM-yyyy')))),3,4)) 
    ELSE CONCAT(CONCAT(year(to_date(from_unixtime(unix_timestamp(dt), 'dd-MM-yyyy')))),'-'),
    SUBSTR(year(to_date(from_unixtime(unix_timestamp(dt), 'dd-MM-yyyy'))))+1,3,4)) end
因为我的dt列不是'dd-mm-yyyy'格式,所以由于某些情况,它没有给出正确的值,我不想使用直接子字符串函数从dt中提取月份部分。我想使用month函数或任何其他函数来获取它,这些函数可以获取month部分,然后根据month部分相应地生成输出列

    Sample Data.
    dt=012019
    output : 2018-19

    dt=022019
    output : 2018-19

    dt=032019
    output : 2018-19

    dt=042019
    output : 2019-20

    dt=052019
    output : 2019-20

    dt=062019
    output : 2019-20

下面的代码为我工作

    CASE WHEN month(to_date(from_unixtime(unix_timestamp(dt,'MMyyyy')))) IN (01,02,03)   
    THEN concat(concat(year(to_date(substr(from_unixtime(unix_timestamp(dt, 'MMyyyy')),1,10)))-1,'-')
    ,substr(year(to_date(from_unixtime(unix_timestamp(dt, 'MMyyyy')))),3,4)) 
    ELSE concat(concat(year(to_date(from_unixtime(unix_timestamp(dt, 'MMyyyy')))),'-'),
    substr(year(to_date(substr(from_unixtime(unix_timestamp(dt, 'MMyyyy')),1,10)))+1,3,4)) END

您正在使用哪个数据库?hive@mkRabbani