查询两个日期和另一个数据

时间:2016-02-18 05:40:11

标签: mysql sql

我需要在两个日期(例如1年)之间按名称显示房屋。我尝试了以下请求,但它不起作用。

SELECT * 
FROM DATA1 
WHERE facility='house' 
    AND datee BETWEEN '2014-02-01' AND '2015-02-31'
GROUP BY name 
ORDER BY datee ASC;

4 个答案:

答案 0 :(得分:0)

这是解决方案!

SELECT * 
FROM DATA1
WHERE facility= 'house'
AND datee BETWEEN '2014-02-01' AND '2015-02-28'
ORDER BY facility,datee ASC

答案 1 :(得分:0)

嗨,你可以使用这些

SELECT * FROM DATA WHERE facility= 'house' 
AND( From_date >= '2013-01-03' AND  To_date <= '2013-01-09')
GROUP BY name 
ORDER BY datee ASC;

答案 2 :(得分:0)

这个解决方案可能对您有所帮助。

SELECT * 
FROM DATA1 
WHERE facility= 'house' 
    AND (cast(datee as date)) BETWEEN (cast('2014-02-01' as date) AND cast('2015-02-28' as date)) 
ORDER BY name, datee ASC;

答案 3 :(得分:-1)

试试这个,它可能对你有帮助。

SELECT * FROM DATA1 
WHERE facility= 'house' 
AND (dateE BETWEEN YEAR(2014-02-01) AND YEAR(2015-02-31) )
GROUP BY name ORDER BY datee ASC;