我有一个名为away
的表,其中包含以下字段
+---------------+-----------------+---------------+
| Name | from | to |
+---------------+-----------------+---------------+
| Lee | 12-09-11 | 16-09-11 |
| | | |
| Mike | 10-10-11 | 12-11-11 |
+---------------+-----------------+---------------+
我需要的是查询一个人是否在某一天离开的查询。例如,Lee
将在14-09-11离开,所以我不想返回这一行。
答案 0 :(得分:2)
set @away:='2011-09-14';
select name
from away
where `from`>@away and `to`<@away;
-- to encourage optimization
-- an index should be build on `from` and `to`
其他问题 - 避免在表架构中使用保留关键字,只是错误
答案 1 :(得分:0)
SELECT * FROM away WHERE '14-09-11' NOT BETWEEN from AND to