2015-10-20 98 views
1

比方說,我已經有了喜歡的一些記錄,我想在那裏TYPE =「本田」和門=「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 =「本田」和門=「4」主要是我不想列出其他類型的IS NOT因爲我不知道他們的價值。

Car.where("type = ? AND doors = ?", "honda", "4") 

回答

1

使用OR操作者選擇其他類型的比「本田」

Car.where("(type = ? AND doors = ?) OR type <> ?", "honda", "4", "honda") 
+0

感謝您的答覆,但什麼是<>? – user2931706

+0

<>是「不等於」運算符。 如果是 –

+0

肯定,謝謝:)你可以upvote並將這個答案標記爲解答。:) – user2931706