得到错误,Mysql2 ::错误:你的SQL语法在rails中有错误?

时间:2016-12-30 12:42:03

标签: ruby-on-rails date where

以下查询需要更改哪些内容?我希望所有那些date_of_leaving为null或date_of_leaving在过去60天之间或date_of_leaving大于或等于Date.today或当前日期的员工。

employees = @company.employees.where('date_of_leaving BETWEEN ? AND ? OR date_of_leaving IS NULL OR date_of_leaving IS >= Date.today', Date.today - 60, Date.today)

我尝试了另外一种方式,如下所示。

employees = Company.find(4).employees.where('date_of_leaving BETWEEN ? AND ? OR date_of_leaving IS NULL OR date_of_leaving IS >= ?', Date.today - 60, Date.today,Date.today)

1 个答案:

答案 0 :(得分:1)

我认为您的问题是短语IS >=

您不应该将is与比较运算符一起使用。只是运营商。取出它,否则看起来不错。