本文介绍了如何在where子句中组合两个条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下内容:
time_range = (1.month.ago.beginning_of_month..1.month.ago.end_of_month) Comment.where(:created_at => time_range).count如何使用如下语句添加到where子句中:
How can I add to the where clause with a statement like:
.where("user_id is not in (?)",[user_ids]).如何将两者结合?谢谢
推荐答案如果您想使用 AND条件查询,请尝试以下操作:
if you want a "AND" conditional query, try this:
Comment. where(:created_at => time_range). where("user_id is not in (?)",[user_ids])其中会产生类似如下的SQL: select ... where ... AND ...
which will produce SQL like : select ... where ... AND ...
如果您需要WHERE子句更复杂,例如:其中(a AND b)或(c AND d),您必须自己将条件合并到子句中,例如
if you want the WHERE clause more complicated, such as: where ( a AND b) OR (c AND d), you have to combine the conditions into the clause yourself, e.g.
Comment.where("(a AND b ) OR (c AND d)")更多推荐
如何在where子句中组合两个条件?
发布评论