sql查询:BETWEEN

时间:2016-11-17 14:04:59

标签: mysql between

我正在尝试执行查询以获取between数据值。

我在这里看到了一些问题,但我的查询更复杂。

这是查询:

SELECT calendar.datefield AS DATE, 
IFNULL( count( lead.insertDate ) , 0 ) AS task
FROM lead 
RIGHT JOIN calendar ON ( DATE( lead.insertDate ) = calendar.datefield ) 
AND lead.lpid =  '40' 
WHERE insertDate BETWEEN '2016-01-05' AND '2016-01-23'
GROUP BY DATE

我认为问题出在查询语法中,查询效果很好,直到我添加where行。

1 个答案:

答案 0 :(得分:1)

您已将条件置于where子句之外。试试这个。

SELECT calendar.datefield AS DATE, 
IFNULL( count( lead.insertDate ) , 0 ) AS task
FROM lead 
RIGHT JOIN calendar ON ( DATE( lead.insertDate ) = calendar.datefield )  
WHERE insertDate BETWEEN '2016-01-05' AND '2016-01-23'
AND lead.lpid =  '40'
GROUP BY DATE