所有
不确定为什么我在运行以下查询时收到错误:
SELECT COUNT(R.id) AS total
FROM request as R
INNER JOIN users AS U ON U.uin = R.engineer_uin
WHERE U.gm = 'BVG1'
AND R.date_received BETWEEN DATE_FORMAT(R.date_received,'%d %m %Y')='01 04 2014' AND DATE_FORMAT(NOW(),'%d %m %Y')
R.date_received
采用以下格式:2015-06-01 14:38:46
我只想在Now()和前一年之间得到结果。 (在英国,我们的财政年度是从4月到明年4月。
错误是:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='01 04 2014' AND DATE_FORMAT(NOW(),'%d %m %Y')
LIMIT 0, 25' at line 5
有什么想法吗?
答案 0 :(得分:2)
The AND
clause you're looking for should look as follows:
...
AND R.date_received BETWEEN STR_TO_DATE('01,04,2014','%d,%m,%Y') AND NOW()