MySQL检查日期范围是否在日期范围内 [英] MySQL Check if date range is in date range

查看:402
本文介绍了MySQL检查日期范围是否在日期范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为小型预订系统执行SQL查询时遇到麻烦,我有一个包含两个条目的表,其中包含两个不同的日期和一个数字.

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.

例如,如果我输入日期2015-01-02和2015-01-04,它将返回Nr 2和 2015-01-05和2015-01-08将返回Nr 1.

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.

推荐答案

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

演示

这篇关于MySQL检查日期范围是否在日期范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆