复杂的SQL查询Rails

时间:2013-04-07 04:55:08

标签: sql ruby-on-rails ruby activerecord rails-postgresql

 Lesson.joins(:custom_attributes).where("custom_attributes.attribute_name_id = 103 AND cast(custom_attributes.value as float) BETWEEN 0 AND 61").where("custom_attributes.attribute_name_id = 103 AND cast(custom_attributes.value as float) BETWEEN 0 AND 61").where("attribute_name_id = 112 AND custom_attributes.value LIKE '%55%'")

以上是我想要实现的一个例子。当我尝试:

Lesson.joins(:custom_attributes).where("custom_attributes.attribute_name_id = 103 AND cast(custom_attributes.value as float) BETWEEN 0 AND 61").where("custom_attributes.attribute_name_id = 103 AND cast(custom_attributes.value as float) BETWEEN 0 AND 61")

它返回正确的记录。但是当我将查询与另一个查询链接时,即使存在满足这两个条件的记录,它也不会获得任何记录。我认为这与选择custom_attributes.attribute_name_id?

有关

0 个答案:

没有答案