dealing with complex query by find_by_sql

Hi    I have a query like sql = "SELECT count(DISTINCT r.id) as req_count, round(SUM(h.assigned_days)/count(DISTINCT r.id),1) as avg_days,h.role_id,EXTRACT(YEAR from r.created_at)||'-'||EXTRACT(MONTH from r.created_at) as period, max(r.created_at) as created_date FROM my_requests r, my_request_histories h WHERE r.id > 0 AND h.my_request_id = r.id GROUP BY period,h.role_id"

Here I get results like req_count | avg_days | role_id | period | created_date