行日之间的SQL日期范围搜索 [英] SQL Date Range search between rows

查看:107
本文介绍了行日之间的SQL日期范围搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下结构的表格



期间名称|开始日期|结束日期

---------------------------------------- -

JAN | 01/01/2013 | 31/01/2013

FEB | 01/02/2013 | 28/02/2013

MAR | 01/03/2013 | 31/03/2013





我想使用开始日期和结束日期进行搜索。例如:我想知道1月15日到2月15日之间的时间段,我应该得到1月和2月。我使用下面的查询尝试了下面的内容,但它显示了我所有的记录





选择* FROM FinancialPeriods WHERE(StartDate> = '15 / 01/2014')或(EndDate< ='15/02/2014')

< br $>


感谢您的快速帮助





提前致谢



Sanaj

I have a table with the following structure

Period Name | Start Date | End Date
------------------------------------------
JAN | 01/01/2013 |31/01/2013
FEB | 01/02/2013 |28/02/2013
MAR | 01/03/2013 |31/03/2013


I want to search using a start date and end date. Ex: I want to know the periods between Jan 15 to Feb 15and I should get Jan and Feb. I tried the below using the below query but it is showing me all the records


Select * FROM FinancialPeriods WHERE (StartDate>='15/01/2014') Or (EndDate<='15/02/2014')


Appreciate your quick help


Thanks in advance

Sanaj

推荐答案

只要符合WHERE子句中的一个条件,OR就会返回记录,试试' AND':

选择* FROM FinancialPeriods WHERE(StartDate> = '15 / 01/2014')和(EndDate< ='15/02/2014')
OR will returns records as long as they meet one of the conditions in the WHERE clause, try 'AND':
Select * FROM FinancialPeriods WHERE (StartDate>='15/01/2014') AND (EndDate<='15/02/2014')


这篇关于行日之间的SQL日期范围搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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