如何将此查询转换为活动记录

How to convert this query into active record

我正在尝试将此查询转换为活动记录,但没有成功。谁能指导我如何将此查询从原始 SQL 转换为活动记录查询

select users.* from
    (
    select email from players_schema.inv_emails where inv_emails.created_at <= (current_date - interval '14 days')
    union
    select email from players_schema.blks where blks.created_at <= (current_date - interval '14 days')
    union
    select email from players_schema.bouces where bouces.created_at <= (current_date - interval '14 days')
    ) email
    join football_schema.users on users.email = email.email; 

我正在使用 rails 4.2

终于找到答案了

User.from("(#{players_schema.inv_emails.to_sql} UNION # 
{players_schema.bouces.to_sql} UNION #{players_schema.blks.to_sql} ) 
AS invalid_emails").joins("INNER join football_schema.users on 
users.email = invalid_emails.email")