要执行范围查询,我们遵循以下语法 -
oms[:order_items].where(:internal_sla => 3..5) results in this query
=> #<Sequel::Mysql2::Dataset: "SELECT * FROM `order_items` WHERE ((`internal_sla` >= 3) AND (`internal_sla` <= 5))">
但是如何更改活动记录查询以给我这样的东西=&gt; select internal_sla from order_items where (internal_sla<=3 and internal_sla>=0) OR (internal_sla<=15 and internal_sla>=10)
答案 0 :(得分:2)
.where("(internal_sla >= ? AND internal_sla <= ? OR
internal_sla >= ? AND internal_sla <= ? )", 0, 3, 10, 15).pluck(:internal_sla)
评论后更新:
如果internal_sla是整数,您可以:
.where(:internal_sla => (0..3).to_a + (10..15).to_a).pluck(:internal_sla)
编辑:修正了错字
答案 1 :(得分:0)
这有效
oms[:order_items].where(:internal_sla => [0..3, 10..15])