我想根据中间时间获取cubbersId
这是我的表:表名cubbersavailability
+---------------------------------------+
|cubbersId | fromTime | toTime |
+---------------------------------------+
| 1 | 09:30:00 | 18:30:00 |
| 1 | 09:30:00 | 18:30:00 |
| 1 | 09:30:00 | 18:30:00 |
| 1 | 09:30:00 | 12:30:00 |
+----------------------------------------+
在上表中,cubbersIsd 有一些时间。
条件
- 如果我选择
fromTime
作为10:30:00
和toTime
作为12:00:00
意味着获取最后 1 列 - 如果我选择
fromTime
作为08:30:00
和toTime
作为16:00:00
意味着不要选择列 - 如果我选择
fromTime
作为10:30:00
和toTime
作为20:00:00
意味着不要选择列 - 如果我选择
fromTime
作为08:30:00
和toTime
作为20:00:00
意味着不要选择列
我试过这个查询,但不支持:
SELECT
c.cubbersId,
shopAvailTime.fromTime,
shopAvailTime.toTime
FROM cubbers c
LEFT JOIN
(SELECT * FROM cubbersavailability ca WHERE CAST('08:30:00' as time) < ca.toTime AND CAST('12:00:00' as time) > ca.fromTime ) as shopAvailTime ON (c.cubbersId = shopAvailTime.cubbersId)
WHERE c.cubbersId = 1
Note: this question already asked but that not help my question;
最佳答案
SELECT x.cubbersId
, x.fromTime
, x.toTime
FROM cubbersavailability x
WHERE '08:30:00' >= x.fromTime
AND '12:00:00' <= x.toTime
AND x.cubbersId = 1
关于mysql - 如何使用 MySql 根据时间间隔获取 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56390119/