让我们说我有一些记录,而且我希望所有的汽车都能在 type =" honda"和门=" 4" 以及所有剩余记录
<Car id="1", type="honda", doors="4" created_at: "2015.01.01">
<Car id="2", type="jeep", created_at: "2015.01.01">
<Car id="3", type="mazda", created_at: "2015.01.01">
<Car id="4", type="honda", doors="4" created_at: "2015.01.01">
<Car id="5", type="honda", doors="2" created_at: "2015.01.01">
<Car id="6", type="honda", doors="2" created_at: "2015.01.01">
我想得到这个:
<Car id="1", type="honda", doors="4" created_at: "2015.01.01">
<Car id="2", type="jeep", created_at: "2015.01.01">
<Car id="3", type="mazda", created_at: "2015.01.01">
<Car id="4", type="honda", doors="4" created_at: "2015.01.01">
我有这个查询,但它只返回 type =&#34; honda&#34;和门=&#34; 4&#34; 主要是我不想列出IS NOT
的其他类型,因为我不确定他们的价值观。
Car.where("type = ? AND doors = ?", "honda", "4")
答案 0 :(得分:1)
使用OR
运算符选择“honda”
Car.where("(type = ? AND doors = ?) OR type <> ?", "honda", "4", "honda")