嗨,大家好,我必须在数据库中查询一些start_datetime和end_datetime,假设将有名称为test的表和列是className,startDateTime和endDateTime如何在开始日期时间和结束日期时间之间查询查询数据
示例数据类名= “I” 的startDateTime = '2017年4月18日八点00分00秒' 和endDateTime = '2017年4月18日9点零零分00秒'
我的查询是一样,如果我的价值就像下面它不应该获取示例数据
startDateTime = 2017-04-18 07:00:00“”并结束日期时间= “2017年4月18日七点55分00秒”
的startDateTime = 2017年4月18日10:00:00 “” 和endDateTime = “2017年4月18日11:00:00”
的startDateTime = 2017年4月19日8点○○分00秒 “” 和endDateTime = “2017年4月19日9点00分零零秒”
应该获取数据。例如
的startDateTime = 2017- 04-18 08:00:00“”and endDateTime =“2017-04-18 09:00:00”
startDateTime = 2017-04-18 08:10:00“”and endD ateTime = “2017年4月18日8点55分00秒”
的startDateTime = 2017年4月18日8时30分○○秒 “” 和endDateTime = “2017年4月18日9点30分○○秒”
SELECT * FROM timetable_tbl WHERE className='I' and
((StartDate>='startDateTimeValue' and StartDate<'startDateTimeValue') or
(StartDate<='startDateTimeValue' and StartDate<'startDateTimeValue') or
(StartDate>='startDateTimeValue' and EndDate<='endDateTimeValue'));
在表格中,开始和结束日期,均为12:00:00。那么为什么要在12:10到12:30之间查询记录? –
对不起,我现在改变了 –
所以事情是......你用'AND'查询2个字段。所以它意味着它会显示那些开始日期大于或等于12:10且结束日期小于或等于12:30的记录。所以两个条件应该匹配以获得结果。但现有记录与第一个条件I.e不匹配。 start_date不大于或等于12:10 –