MySQL:比较时间 [英] MySQL: Compare BETWEEN time
本文介绍了MySQL:比较时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按照我想使其工作的方式,这可能是不可能的,但是可以了.
This may be impossible in the way that I'd like to have it work, but here goes.
SELECT * FROM `table` WHERE CAST('05:00:00' AS time) BETWEEN `start` AND `end`
数据库中的条目为:
`start` = '22:59:59'
`end` = '06:00:00'
但是,查询不返回任何结果.当然,如果涉及到日期,这将起作用,但是没有涉及.如果开始= '00:00:00',它也将起作用.
However, the query returns no results. Of course, this would work if there were dates involved, however there are not. It would also work if the start was = '00:00:00'.
推荐答案
我认为您正在寻找的是:
i think what you are looking for is:
SELECT * FROM table WHERE start < CAST('05:00:00' AS time) AND end > CAST('05:00:00' AS time)
我不确定是否需要使用 CAST ,尽管这也应该起作用.
I'm not sure if you need to use the CASTs, though this should also work.
SELECT * FROM table WHERE start < '05:00:00' AND end > '05:00:00'
这篇关于MySQL:比较时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文