Topic: Converting SQL Query to RubyonRails Model! Need Help!

Hi, I have this following SQL Query:

select
event_type as 'Type'
,event_category as 'Category'
,(select item_count from rbms_d.ddt_events tbl2
  where tbl2.event_type = tbl1.event_type
    and tbl2.event_category = tbl1.event_category
    and tbl2.event_source = 'RBAC'
) as RBAC
,(select item_count from rbms_d.ddt_events tbl2
  where tbl2.event_type = tbl1.event_type
    and tbl2.event_category = tbl1.event_category
    and tbl2.event_source = 'RBMS'
) as RBMS
from rbms_d.ddt_events tbl1
group by event_type, event_category;

*I need help converting the SQL Query to RubyonRails Model.*

Thanks