我有一个 datetime
列。如何获取 Date
列在两个特定时间之间的行(无论日月年)。
例如,小时在 14:00:00
和 15:00:00
之间(所有天)的任何行?
最佳答案
您可以使用time()
或hour()
:
where hour(datetime) >= 14 and hour(datetime) < 16
或:
where time(datetime) >= '14:00:00' and time(datetime) < '16:00:00'
或者您可能更喜欢这样:
where time(datetime) >= '14:00:00' and
time(datetime) < '15:00:00' + interval 1 hour
注意:由于 datetime
列上的函数调用,这些都不会使用索引。
关于mysql - 如何从日期时间列中获取两小时之间的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58392963/