当前位置:首页 > 数据库 > Oracle

Oracle取当前日期的最近工作日

  描述:现有一需求,日期表中存放了日期和是否节假日(0-工作日,1-节假日),现在需要取日期表中的最近的工作日。如2017/07/23(周日)最近的工作日应该是2017/07/21(周五)。
       DATE_D    IS_HOLIDAY
1    2017/7/17    0
2    2017/7/18    0
3    2017/7/19    0
4    2017/7/20    0
5    2017/7/21    0
6    2017/7/22    1
7    2017/7/23    1
8    2017/7/24    0
9    2017/7/25    0
select t1.date_d,max(t2.date_d)
from table_a t1 left join table_a t2 on (t1.date_d >= t2.date_d and t2.is_holiday=‘0‘)
group by t1.date_d
order by t1.date_d

结果:

 

       DATE_D    MAX(T2.DATE_D)
1    2017/7/17    2017/7/17
2    2017/7/18    2017/7/18
3    2017/7/19    2017/7/19
4    2017/7/20    2017/7/20
5    2017/7/21    2017/7/21
6    2017/7/22    2017/7/21
7    2017/7/23    2017/7/21

原文:http://www.cnblogs.com/littlewu/p/7218871.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐