如何将以下 sql 查询转换为 Arel?
SELECT
SUM(
LEAST(
SPONSORSHIPS.AMOUNT_PER_LAP * (
SELECT
SUM(LAPS.POINTS)
FROM
LAPS
WHERE
LAPS.CAMPAIGN_ID = :j_id
),
SPONSORSHIPS.MAX_AMOUNT
)
)
FROM
SPONSORSHIPS
WHERE
SPONSORSHIPS.CAMPAIGN_ID = :j_id;
有3个表/模型。jogathons
, sponsorships
, 和laps
. :j_id
是jogathon id。