暂无图片
oracle中有张表year,month保存年月,这个结构如何按某个时间范围查询?
我来答
分享
暂无图片 匿名用户
oracle中有张表year,month保存年月,这个结构如何按某个时间范围查询?

oracle中有张表year,month保存年月,这个结构如何按某个时间范围查询?

我来答
添加附件
收藏
分享
问题补充
3条回答
默认
最新
DarkAthena

假设你的年是4位字符,比如'2021';月是2位字符,比如'02'。如果要查询2021年1月到2021年5月,则

select * from tab where year||month between '202101' and '202105';

或者

select * from tab where to_date(year||month,'yyyymm') between date'2021-01-01' and date'2021-05-31';

暂无图片 评论
暂无图片 有用 0
打赏 0
暂无图片
Thomas

where year||month between '202101' and '202105'; 最好对year||month建立函数索引。

暂无图片 评论
暂无图片 有用 0
打赏 0
赵勇

如果不跨年,也可以分别查。比如 year='2021' and month between 1 and 5

暂无图片 评论
暂无图片 有用 0
打赏 0
回答交流
Markdown


请输入正文
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏