Person.calculate(:count, :all) # The same as Person.count
Person.average(:age) # SELECT AVG(age) FROM people...
# Selects the minimum age for any family without any minors
Person.group(:last_name).having("min(age) > 17").minimum(:age)
Person.sum("2 * age")

There are two basic forms of output:

Single aggregate value: The single value is type cast to Integer for COUNT, Float for AVG, and the given column's type for
everything else.

Grouped values: This returns an ordered hash of the values and groups them.
It takes either a column name, or the name of a belongs_to association.

Person.count
# => the total count of all people
Person.count(:age)
# => returns the total count of all people whose age is present in database
Person.count(:all)
# => performs a COUNT(*) (:all is an alias for '*')
Person.distinct.count(:age)
# => counts the number of different age values

If count is used with Relation#group, it returns a Hash whose keys represent the aggregated column,
and the values are the respective amounts:

Person.group(:city).count
# => { 'Rome' => 5, 'Paris' => 3 }

If count is used with Relation#group for multiple
columns, it returns a Hash whose keys are an
array containing the individual values of each column and the value of each
key would be the count.