Before the network query about the use of SQL query "date after a few days" question, the effect is, assuming today is Wednesday (2014/08/27), after three business days (including Wednesday) is Friday (20140929), four business days later, It is next Monday (20140901), if the legal holidays, when the weekend processing (such as Monday is the mid-Autumn Festival, Monday is not a weekday). Read a few replies, feel the realization is quite complicated, today learned a relatively simple approach, I hope it is good for you.
Create a timesheet SJB, formatted as follows:
Date (TJRQ) |
Holiday Types (type) |
YYYYMMDD |
0 working days, 1 regular weekends, 2 holidays. |
Holidays, can be legal holidays, can also be customized special holidays.
For the timetable, we need to pre-set the database for the entire year or years of data, that for the query out (today) three working days after the date, in fact, the query date type is 1, the next third data can, in order to be more efficient, you can consider paging to achieve.
Queries such as those on Oracle can be: (in the actual implementation, it is often necessary to pass in today's date (20140828), the first few days 3)
SELECT * FROM (select r.*, RowNum rn from (
Select Tjrq from SJB where Tjrq >= 20140828 and type= 0 ORDER by TJRQ ASC
) R where Rownum<=3) pg where pg.rn= 3
The query on MySQL is as follows:
Select Tjrq from SJB where Tjrq >= 20140828 and type= 0 ORDER by TJRQ ASC limit 3,1
In view of the need to pre-initialize the data, need to occupy a certain amount of database space, but only a year more than 300 data, such storage space, is not considered.
SQL query dates after a few working days