SQL query, the week is queried based on the date range

Source: Internet
Author: User

The week data will have WeekBegin and weekend two fields that describe the start and end dates of the week.

Now the Calendar control in the project does not support the weekly query, only the date query, so the current problem is, according to the time range, query week.

The final SQL is as follows:


and date (weekend) <=date (' 2018-05-31 ')) or (date (weekbegin) <= (' 2018-05-01 ') and date (weekend) >=date (' 2018-05-31 ')) GROUP by Uid,weekbegin,weekend

  

Use the exhaustive method to do the processing, that is, to list out all the circumstances of the or query.

Simply say the logical thinking process:

The week start time End Time field is Weekbegin,weekend

The time range for page queries is begindate and enddate

Then the order of the four Time fields may be:

WeekBegin Weekend Begindate EndDate

1 2 3 4

1 3 2 4

1 4 2 3

2 3 1 4

3 4 1 2

The above SQL is finally drawn

SQL query, the week is queried based on the date range

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.