Ruby On Rails Complex Sql Postgres Query Into Activerecord Notation

Ruby On Rails Complex Sql Postgres Query Into Activerecord Notation