我在 MySQL 中有这个查询,我需要将它转换为 rails 活动记录:
select p.*,x.* from
(select * from users ,roles_users
where users.id=roles_users.user_id and roles_users.role_id not in(2,3)) as P
left join
(select *
from cad_dispaths as T
where `startdate_dispatch` =
( select max(`startdate_dispatch`)
from cad_dispaths
where users_id = T.users_id )) x
on x.users_id = p.user_id