1

如何在 ruby​​ 中编写以下查询。

select count(*), project_types.project_type_name,company_id from project_type_stages_questions,project_types where (project_type_stage_id in 
(select project_type_stages_id from project_type_stages where project_type_id in (select project_type_id from project_types))) group by project_type_stage_id,project_types.project_type_name,company_id
4

1 回答 1

0

如果你有一个复杂的 sql 要做,并且你打算使用它的结果,你可以将它传递给 db manager:

sql = "select count(*), project_types.project_type_name,company_id from project_type_stages_questions,project_types where (project_type_stage_id in (select project_type_stages_id from project_type_stages where project_type_id in (select project_type_id from project_types))) group by project_type_stage_id,project_types.project_type_name,company_id"
ActiveRecord::Base.connection.execute(sql)

公共 api 没有提供太多信息,但它就在这里

如果您需要 ActiveRecord::Relation 作为结果,我建议他们使用 Arel。

于 2015-03-24T00:02:58.607 回答