Mysql查询中的1064 Sql语法错误

时间:2015-11-20 11:47:45

标签: mysql

我在Mysql中遇到sql语法错误。我哪里错了? 我的查询是,

SELECT *
FROM `fx_users_attendance`
   LEFT OUTER JOIN `fx_account_details` ON fx_account_details.user_id = fx_users_attendance.user_id
   LEFT OUTER JOIN `fx_departments` ON fx_departments.deptid = fx_account_details.department
   LEFT OUTER JOIN `fx_users` ON fx_users.id = fx_users_attendance.user_id
WHERE fx_departments.deptid IN("1")
      AND fx_users.id ="5"
      AND date(fx_users_attendance.clock_in) BETWEEN (date(fx_users_attendance.clock_in) >= "2015-10-20"
      AND date(fx_users_attendance.clock_in) <= "2015-11-10")

1 个答案:

答案 0 :(得分:1)

您错过了解BETWEEN

的语法

date(fx_users_attendance.clock_in) BETWEEN (date(fx_users_attendance.clock_in) >= "2015-10-20" AND date(fx_users_attendance.clock_in) <= "2015-11-10")

应改为

date(fx_users_attendance.clock_in) BETWEEN '2015-10-20' AND '2015-11-10'

SELECT * 
FROM `fx_users_attendance`
 LEFT OUTER JOIN `fx_account_details` ON fx_account_details.user_id = fx_users_attendance.user_id 
 LEFT OUTER JOIN `fx_departments` ON fx_departments.deptid = fx_account_details.department 
 LEFT OUTER JOIN `fx_users` ON fx_users.id = fx_users_attendance.user_id 
 WHERE fx_departments.deptid IN("1") AND fx_users.id ="5" AND date(fx_users_attendance.clock_in) BETWEEN '2015-10-20' AND '2015-11-10'

希望这有帮助。