date - 计算蜂巢中两个日期之间的月份
问题描述
我试图找出 currentdate 和列 (emp_joined) 之间的月份差异小于 24 个月。emp_joined 列的数据类型是 int。为此,我编写了以下查询来获取记录。
select id,emp_joined from table where (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)))<24)
但是该查询返回当前日期和列 emp_joined 之间不少于 24 个月的所有记录。谁能帮我查询。
解决方案
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
推荐阅读
- php - pg_query():查询失败:SSL SYSCALL 错误:在 php 脚本中检测到 EOF
- c# - Dispatcher.CurrentDispatcher 导致 ReactiveUI 调用挂起
- android - 在改造 2 中获得响应代码为 500 的空响应
- firebase - 在服务器端验证 Firebase 令牌的安全问题?
- python - 无法使用 pandas 读取 .txt 文件
- python - 为什么 pkgutil 风格的命名空间包缺少 __init__.py?
- git - 过时的 PR 差异
- javascript - 当散列锚在 URL 中时显示选择 DIV
- c# - 如何为 AvalonEdit (ICSharpCode) 文本编辑器控件创建事件处理程序?
- c# - 从数据库表中检索数据并在标签中获取其值时出错