我有桌面材料:
我有这些数据:
1, title1, 2016-06-02
2, title2, 2016-06-02
3, title3, 2016-06-03
4, title4, 2016-06-03
5, title6, 2016-06-03
6, title7, 2016-06-05
7, title8, 2016-06-05
8, title9, 2016-06-06
9, title10, 2016-06-06
10, title11, 2016-06-06
11, title11, 2016-06-07
12, title12, 2016-06-08
我想知道2016-06-02和2016-06-06之间date_operation的所有材料:
我试着用这个:
SELECT * FROM `material` WHERE date_operation = '2016-06-02' AND '2016-06-06'
但是告诉我这个结果:
1, title1, 2016-06-02
2, title2, 2016-06-02
3, title3, 2016-06-03
4, title4, 2016-06-03
5, title6, 2016-06-03
6, title7, 2016-06-05
7, title8, 2016-06-05
我希望看到这样的结果:
1, title1, 2016-06-02
2, title2, 2016-06-02
3, title3, 2016-06-03
4, title4, 2016-06-03
5, title6, 2016-06-03
6, title7, 2016-06-05
7, title8, 2016-06-05
8, title9, 2016-06-06
9, title10, 2016-06-06
10, title11, 2016-06-06
答案 0 :(得分:5)
试试这个
SELECT *
FROM `material`
WHERE (date_operation BETWEEN '2016-06-02' AND '2016-06-06')
答案 1 :(得分:5)
使用三元运算符快速执行MYSQL查询的最佳方法。试试这个: -
`SELECT * FROM material WHERE date_operation >= '2016-06-02' AND date_operation <= '2016-06-06'`;
答案 2 :(得分:1)
您可能在“日期”值上有时间组件。 BETWEEN
对日期很危险。我建议:
SELECT *
FROM `material`
WHERE date_operation >= '2016-06-02' AND date_operation < '2016-06-07';
无论值是否具有时间成分,这都将起作用。
您也可以使用date()
函数(偶数为between
),但这可能会妨碍索引的使用。
答案 3 :(得分:0)
试试这个:
SELECT * FROM `material` WHERE date_operation BETWEEN '2016-06-02 00:00:00' AND '2016-06-06 23:59:59'
答案 4 :(得分:0)
<强> TryThis 强>
SELECT * FROM `material` WHERE date_operation >= '2016-06-02' AND date_operation <='2016-06-06'