GavinBelson
GavinBelson

Reputation: 2794

Rails: ActiveRecord custom average calculation

Outside of using a raw SQL query, is there a nice way to divide an active record query result by a constant? A variable?

Example:

Phones.group(:year).order(:year).average(:talk_time_min)

If I wanted to retrieve the talk_time_min in seconds, how could I do talk_time_min / 60?

Upvotes: 0

Views: 167

Answers (1)

potashin
potashin

Reputation: 44601

Like this:

Phones.group(:year).order(:year).average('talk_time_min/60')

Upvotes: 1

Related Questions