我在mysql表中有一个行列表
+--------+-----+------------+------------+------------+-----------+ | off_id | uid | leave_from | leave_to | leave_code | reason | +--------+-----+------------+------------+------------+-----------+ | 1 | 1 | 2012-01-01 | 2012-01-05 | OFF | asdsda | | 2 | 1 | 2012-01-15 | 2012-01-16 | OFF | asdd | | 5 | 1 | 2012-02-03 | 2012-02-05 | OFF | gfjghjhgj | +--------+-----+------------+------------+------------+-----------+
我必须选择日期2012-01-01到2012-01-05之间的行。 我该怎么做才能帮忙。
答案 0 :(得分:3)
SELECT *
FROM tbl
WHERE leave_from >= '2012-01-01'
AND leave_to <= '2012-01-05'
答案 1 :(得分:2)
select * from table where leave_from between '2012-01-01' and '2012-01-05'
答案 2 :(得分:1)
SELECT Off_Id,uid,Leave_from,leave_to,leave_code
FROM YourTableName
WHERE Leave_From>="2012-01-01" and Leave_to <="2012-01-05"
答案 3 :(得分:1)
如果我理解你的问题:
SELECT * FROM `table_name`
WHERE leave_from >= "2012-01-01" AND leave_to <= "2012-01-05"
答案 4 :(得分:0)
第1点:你可以使用&gt; &LT; &lt; =&gt; =使用date数据类型。
以上可以通过
来实现SELECT * FROM table WHERE leave_from > '2012-01-01' AND leave_from <'2012-01-05';