在两个日期之间输出mysql [英] Output between two dates mysql

查看:53
本文介绍了在两个日期之间输出mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要像这样在MYSQL中出局.

记录:

start_date |  to_date
2013-01-01 | 2013-12-31
2013-02-01 | 2013-05-04
2013-01-30 | 2013-04-02
2013-04-30 | 2013-07-06
2013-06-30 | 2013-06-09
2013-08-30 | 2013-10-03

我的输入日期为2013年4月1日至2013年6月10日.

我的输出应该是这样的:

start_date | to_date
2013-01-01 | 2013-12-31
2013-02-01 | 2013-05-04
2013-01-30 | 2013-04-02
2013-04-30 | 2013-07-06
2013-06-30 | 2013-06-09

在这方面可以有任何帮助.

解决方案

似乎要查找与给定范围重叠的范围;

SELECT * FROM date_table 
WHERE start_date < '2013-06-10'
  AND to_date   > '2013-04-01'

也就是说,您将from_date与to_date列进行比较,并将to_date与start_date列进行比较.

要测试的SQLfiddle .

I need the out in MYSQL like this.

Records :

start_date |  to_date
2013-01-01 | 2013-12-31
2013-02-01 | 2013-05-04
2013-01-30 | 2013-04-02
2013-04-30 | 2013-07-06
2013-06-30 | 2013-06-09
2013-08-30 | 2013-10-03

my input is from_date 2013-04-01 and to_date 2013-06-10

my out put shuld be like this :

start_date | to_date
2013-01-01 | 2013-12-31
2013-02-01 | 2013-05-04
2013-01-30 | 2013-04-02
2013-04-30 | 2013-07-06
2013-06-30 | 2013-06-09

can any one help on this.

解决方案

Seems you want to find ranges overlapping your given range;

SELECT * FROM date_table 
WHERE start_date < '2013-06-10'
  AND to_date   > '2013-04-01'

That is, you compare your from_date with the column to_date and your to_date with the column start_date.

An SQLfiddle to test with.

这篇关于在两个日期之间输出mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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