我想在日期之间获取数据。我有一些来自和迄今的记录。现在我想用日期检查该记录。
Employee Leave_from_date Leave_to_date Leave_Type
001 06-10-2012 07-10-2012 Casual
我想使用像这样的
这样的select语句 Select * from leave_request where fldempid=001 as L on fldfromdate
>= 06-10-2012 and fldtodate<='06-10-2012'
如果使用07-10-2012意味着再次显示上述记录。
请帮我创建这个......
答案 0 :(得分:4)
在between
子句中反转值和列的通常位置:
select *
from leave_request
where fldempid = 001
and '06-10-2012' between fldfromdate and fldtodate
答案 1 :(得分:0)
试试这个:
SELECT Employee, Leave_from_date, Leave_to_date, Leave_Type
FROM leave_request
WHERE fldempid = 001 AND
DATE('06-10-2012') between fldfromdate and fldtodate
答案 2 :(得分:0)
我建议先将日期转换为unix时间戳,以便使用<=
>=
运算符进行安全比较
e.g
SELECT
Employee, Leave_Type
UNIX_TIMESTAMP(fldfromdate) AS Leave_from_date,
UNIX_TIMESTAMP(fldtodate) as Leave_to_date
FROM
leave_request
where
fldempid=001 as L on
Leave_from_date>=1349481600 and Leave_to_date<=1349481600;
没有尝试过上述内容,但应该使用一些推文...