select * from people where id in (select id from people where age>50)
下边的ruby on rails代码会把上边的代码转换成ruby能识别的
id_arr = (people.where('age>?', 50)).map(&:id).uniq
res = people.where(:id => id_arr)
这里的map将选出来的active recordlist中的id项转换成一个array,uniq是去掉其中的重复项

本文详细解析了如何将SQL查询语句转换为Ruby on Rails代码,包括使用ActiveRecord方法实现复杂查询的过程,以及如何利用Ruby的map和uniq方法对查询结果进行操作。

691

被折叠的 条评论
为什么被折叠?



