我想产生类似下面的使用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