SQL query dates after a few working days

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.