我想根据时间间隔获取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 |
+----------------------------------------+
在上面的表中,cubbersIs有一段时间。
条件
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
注意:这个问题已经问过了,但对我的问题没有帮助;
答案 0 :(得分:1)
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