计算蜂巢中两个日期之间的月份

问题描述

我试图找到currentdate和column(emp_joined)之间的月份差异小于24个月。 列emp_joined的数据类型为int。为此,我编写了以下查询获取记录。

从表中选择id,emp_joined (abs(month_between(cast(from_unixtime(unix_timestamp(current_date,'yyyy-MM-dd'),'yy-MM-dd'),from_unixtime(unix_timestamp(cast(emp_joined as string),'yyMMdd'),'yy- MM-dd')as int))))

但是查询返回的所有记录在currentdate和emp_joined列之间不少于24个月。 任何人都可以帮助我进行查询

enter image description here

解决方法

months_between接受yyyy-MM-dd格式的日期。试试这个

where abs(cast(months_between(current_date,from_unixtime(unix_timestamp(cast(emp_joined as string),'yyMMdd'),'yyyy-MM-dd')
              )as int)) < 24