MySQL Check if date range is in date range

岁酱吖の 提交于 2019-11-28 12:50:40

问题


Having trouble making a SQL query for a small booking system, i have a table containing two entries which holds two different dates and a number.

Nr    DateFrom      DateTo
----------------------------
1    2015-01-01   2015-01-03
2    2015-01-05   2015-01-08

I want to query where i can enter two different dates and only return the number of the date range in the table that doesn't collide with the entered date range.

For example if i enter the dates 2015-01-02 and 2015-01-04 it would return Nr 2 and 2015-01-05 and 2015-01-08 would return Nr 1.


回答1:


SELECT *
FROM yourTable
WHERE DateFrom > @rangeEnd OR DateTo < @rangeBegin

DEMO



来源:https://stackoverflow.com/questions/29727998/mysql-check-if-date-range-is-in-date-range

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!