如何在指定的时间范围内在mysql中找到结果? [英] how to find results in mysql within the specfied times range?
本文介绍了如何在指定的时间范围内在mysql中找到结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的桌子
ID开始时间结束时间
1 09:00:00 10:00:00
1 09:00:00 10:00:00
2 10:30:00 11:00:00
2 10:30:00 11:00:00
3 14:30:00 16:00:00
3 14:30:00 16:00:00
如何检查传递的日期范围是否介于开始时间和结束时间之间...就像我说的那样,如果开始时间为 09:24:00 并且结束时间为 09: 56:00 ?它应该返回1的Id值
How to check the if passed date ranges fall in between the Start and End Times...like when i say, if starttime is 09:24:00 and endtime is 09:56:00? it should return Id value of 1
您能帮我吗?
推荐答案
使用 BETWEEN (如果值是between
另外两个值).请注意,比较之间包括边界.
Use BETWEEN if a value is between
two other values. Note that BETWEEN comparison includes the borders.
WHERE `time` BETWEEN `StartTime` AND `EndTime`
当然不要忘记
CAST(`time` AS TIME)
如果它不是TIME
类型.
要检查范围:
WHERE
(CAST(`rangeStart` AS TIME) BETWEEN `StartTime` AND `EndTime`) AND
(CAST(`rangeEnd` AS TIME) BETWEEN `StartTime` AND `EndTime`)
这篇关于如何在指定的时间范围内在mysql中找到结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文