SQL statements: Two time interval segments, as long as there is a intersection, you can filter out

Source: Internet
Author: User

Set fixed time period: 8.2---"8.5

That is: two time periods, as long as the intersection can be filtered out:

The following two SQL statements achieve the same effect:

1: $sql = "SELECT * from Fs_ads where ' start_time ' <= ' $ed ' and ' end_time ' >= ' $sd '";

2:

$sql = "SELECT * FROM (
Select Ads_id,file_id,client_type,client_name,brand,model,cal_type Start_time,end_time,
Case
When (start_time>= ' $SD ') then start_time
When (start_time< ' $sd ') Then ' $SD '
End as Start1,
Case
When (end_time>= ' $ed ') Then ' $ed '
When (end_time< ' $ed ') then End_time
End as End1
From Fs_ads)
A Where a.start1<=a.end1;
"; Note: $SD, $ed is the time selected by the user reference: http://www.cnblogs.com/hupengyin/p/6051145.html

SQL statements: Two time interval segments, as long as there is a intersection, you can filter out

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.