Average number of days since a date in postgresql/rails -
i want calculate average number of days since 'date_from' (it varies)
user.all.average('? - date_from', time.now.to_date)
gives error
undefined method `except' thu, 27 nov 2014:date
see ruby_on_rails/activerecord/calculations
the second parameter of average
options(an hash)
the options can used customize query :conditions, :order, :group, :having , :joins.
so should generate average expression this:
user.average("'#{time.now.to_date}' - date_from" )
then rails generate sql this:
select avg('2014-11-27' - date_from) avg_id ...
Comments
Post a Comment