Rails SQL查询与find

前端之家收集整理的这篇文章主要介绍了Rails SQL查询与find前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我希望使用find在rails控制器中编写这个SQL查询
select id,name from questions
where id not in (select question_id from levels_questions where level_id=15)

我该怎么做?我正在使用Rails框架和MysqL.
提前致谢.

解决方法

简单方法
ids = LevelsQuestion.all(:select => "question_id",:conditions => "level_id = 15").collect(&:question_id)
Question.all(:select => "id,name",:conditions => ["id not in (?)",ids])

一枪:

Question.all(:select => "id,:conditions => ["id not in (select question_id from levels_questions where level_id=15)"])
原文链接:https://www.f2er.com/mssql/83492.html

猜你在找的MsSQL相关文章