我有桌子
ID NAME STIME ETIME
1 S-1 07:01:00 15:29:29
2 S-2 15:30:00 22:59:59
3 S-3 23:00:00 07:00:59
当我输入时间时,我需要获取NAME
我的查询
SELECT ID, NAME
FROM TABLE
WHERE '08:00:00' BETWEEN STIME AND ETIME
正常情况下可以正常工作 但是如果它的S-3错了
SELECT ID, NAME
FROM TABLE
WHERE '04:00:00' BETWEEN STIME AND ETIME
我需要获得S-3行
我该如何查询? 谢谢
答案 0 :(得分:0)
您可以使用:
WHERE (STIME < ETIME AND '04:00:00' BETWEEN STIME AND ETIME) OR
(STIME > ETIME AND '04:00:00' NOT BETWEEN ETIME AND STIME
)
这考虑了两种可能性。