【问题标题】:where :thisyear > :last unless :last nil?哪里 :thisyear > :last 除非 :last nil?
【发布时间】:2013-09-17 21:54:32
【问题描述】:

我的 rails 应用中有一个 sql 搜索查询:

 patients = patients.where("thisyear < last ") if search.present?

我的问题是这个搜索查询还取消选择 :last 为 nil 的数据库条目

我的问题是我如何编写一个搜索查询,该查询不适用于 :last 列为 nil 的患者?谢谢

【问题讨论】:

    标签: sql ruby-on-rails ruby ruby-on-rails-3


    【解决方案1】:

    patients = patients.where("last IS NULL OR thisyear &lt; last") if search.present?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 2017-03-04
      • 1970-01-01
      相关资源
      最近更新 更多