我想產生類似下面的使用Ruby的續集SQL查詢:如何將「和」和「或」結合起來使用續集?
SELECT * FROM Objects WHERE (color = "red" AND shape = "triangle") OR
(color = "blue" AND shape = "square") OR
(color = "green" AND shape = "circle")
我想從一個條件列表編程方式創建此查詢,這樣我可以做這樣的事情:
conditions = [[[:color, "red"], [:shape, "triangle"]],
[[:color, "blue"], [:shape, "square"]],
[[:color, "green"], [:shape, "circle"]]]
DB[:Users].where(conditions.sql_or)
它不一定要遵循確切的形式,但我希望能夠以編程方式構建條件,所以僅靠手工構建此查詢是不夠的。
*使用SQL *生成SQL查詢...您剛剛向我們展示了SQL查詢。你能澄清你的要求嗎? – Kermit
@njk用「Ruby's Sequel」替換第二個「SQL」。我已經應用了一個編輯。 – iain