【问题标题】:Ruby Rails - Query by Date MonthRuby Rails - 按日期月份查询
【发布时间】:2015-09-16 15:38:46
【问题描述】:

我想选择游戏表中日期列具有月份大于 6 的条目的所有条目。游戏表的列是 date_column、id、wining_side、status、away_score、home_score。数据库是 Postgres。类似的东西

Game.where("date_part(month, date_column) > ?", 6)

date_part 似乎是正确的 SQL 函数,但它失败了。

【问题讨论】:

  • Game 表中有哪些列? - date_column 是什么?
  • 它是怎么失败的?你期待什么,你得到什么?错误信息?

标签: sql ruby-on-rails ruby where


【解决方案1】:

“月”参数使用引号:

Game.where("date_part('month', date_column) > ?", 6)

【讨论】:

    【解决方案2】:

    您需要用单引号将月份一词括起来,即

    Game.where("date_part('month', date_column) > ?", 6)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 2010-10-18
      • 2013-09-25
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多