SELECT rs.id as rs_id,
sum(rs.amount_per_month) as rs_am1,
sum(rs.amount_per_month_per_sqft) as rs_am2,
rs.from_date,rs.to_date,cc.charge_type as cc
FROM lease_rent_rolls as lrr
INNER JOIN leases as l ON lrr.lease_id = l.id
INNER JOIN rents as r ON l.id = r.lease_id
INNER JOIN rent_schedules as rs ON r.id = rs.rent_id
INNER JOIN charge_codes as cc ON rs.charge_code_id = cc.id
WHERE lrr.id = 449443
AND DATE(NOW()) BETWEEN rs.from_date AND rs.to_date
GROUP BY cc.charge_type
我在模型中使用此SQL查詢中使用find_by_sql
,但我應該得到這個同樣的結果在Ruby中加入WHERE條件在模型中沒有的幫助SQL。如何寫的Ruby這個sql查詢加入查詢(Ruby on Rails的)
您能否向我們展示您的模型,包括它們之間的關聯? – BroiSatse
請分享您的模特協會,然後它會更有幫助。 – uma