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是去掉其中的重复项