嗨,我有“sql查询”,以查看上周每个成员完成的工作的数量,所以我创建“sql查询”,这是非常的工作,但我想将周期从1周或周2更改为此数据我的“sql查询”是:
SELECT `staffID`,
SUM(if (created_at BETWEEN NOW()-INTERVAL 1 WEEK AND NOW(), 1,0))
AS `week1`,
SUM(if (created_at BETWEEN NOW()-INTERVAL 2 WEEK AND NOW()-INTERVAL 1 WEEK, 1,0))
AS `week2`,
FROM tasks where status ='done'
GROUP BY `staffID
我想成为这样的“SQL查询”,但mysql给我错误.那么,无论如何要解决这个问题?
SELECT `staffID`,
SUM(if (created_at BETWEEN NOW()-INTERVAL 1 WEEK AND NOW(), 1,0))
AS NOW()-INTERVAL 1 WEEK,
SUM(if (created_at BETWEEN NOW()-INTERVAL 2 WEEK AND NOW()-INTERVAL 1 WEEK, 1,0))
AS NOW()-INTERVAL 2 WEEK,
FROM tasks where status ='done'
GROUP BY `staffID
sql给我这条消息:
1064 – 您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在’NOW()附近使用正确的语法 – INTERVAL 1 WEEK