我有以下幾點:如何在where子句中結合兩個條件?
time_range = (1.month.ago.beginning_of_month..1.month.ago.end_of_month)
Comment.where(:created_at => time_range).count
我如何添加到where子句中包含一個聲明:
.where("user_id is not in (?)",[user_ids]).
我怎樣才能將二者結合起來?感謝
如果你想我有以下幾點:如何在where子句中結合兩個條件?
time_range = (1.month.ago.beginning_of_month..1.month.ago.end_of_month)
Comment.where(:created_at => time_range).count
我如何添加到where子句中包含一個聲明:
.where("user_id is not in (?)",[user_ids]).
我怎樣才能將二者結合起來?感謝
如果你想「AND」 條件查詢,試試這個:
Comment.
where(:created_at => time_range).
where("user_id is not in (?)",[user_ids])
將產生SQL這樣的:select ... where ... AND ...
如果希望WEHRE條款比較複雜
,如:where (a AND b) OR (c AND d)
,你必須自己將條件合併到條款中,例如
Comment.where("(a AND b) OR (c AND d)")
User.where(name: 'Joe', email: '[email protected]')
錯誤w ActiveRecord :: StatementInvalid:PG :: Error:ERROR:語法錯誤在或在「 – AnApprentice