次のようにActiveRecordでサブクエリを使用したいと思います。
User.select(
'users.*,
(select sum(amount)
from subscriptions
where subscriptions.user_id = user.id
and created_at < ? ) as amt)'
).order('amt')
ただし、最後から2行目では、のメソッドが複数のパラメーター(SQL文字列)を受け入れないため、Time
クラスパラメーターをバインドする方法がわからないという問題があります。私は何をしますか?ActiveRecord::Base
select