我正在尝试从日期范围以及办公室面积等于office->id area
的地方获取数据。这是我的查询
SELECT * FROM office as d
LEFT JOIN office_area as e ON e.ID_Area = d.ID_Area
WHERE d.ID_Area = 1 OR d.ID_Area = 6
AND d.date BETWEEN '2018-09-01' AND '2018-09-30'
ORDER BY d.date DESC
问题在于获取日期为2018-01-01
的数据是因为第一个位置。如何才能从该日期范围的1
和6
区域中获取数据
答案 0 :(得分:0)
您需要添加一些括号以对逻辑进行排序:
SELECT * FROM office as d
LEFT JOIN office_area as e ON e.ID_Area = d.ID_Area
WHERE (d.ID_Area = 1 OR d.ID_Area = 6)
AND (d.date BETWEEN '2018-09-01' AND '2018-09-30')
ORDER BY d.date DESC