module Jennifer::QueryBuilder::Aggregations
Overview
Contains aggregation query functions.
Direct including types
Defined in:
jennifer/query_builder/aggregations.crInstance Method Summary
- 
        #avg(field, klass : T.class) : T forall T
        
          Returns average value of the field field of type klass. 
- 
        #count : Int32
        
          Returns result row count. 
- 
        #group_avg(field, klass : T.class) : Array(T) forall T
        
          Returns array of average values of the field field of type klass in groups. 
- 
        #group_count(field)
        
          Returns array of counts values of the field field of type klass in groups. 
- 
        #group_max(field, klass : T.class) : Array(T) forall T
        
          Returns array of maximum values of the field field of type klass in groups. 
- 
        #group_min(field, klass : T.class) : Array(T) forall T
        
          Returns array of minimum values of the field field of type klass in groups. 
- 
        #group_sum(field, klass : T.class) : Array(T) forall T
        
          Returns array of values sums of the field field of type klass in groups. 
- 
        #max(field, klass : T.class) : T forall T
        
          Returns maximum value of the field field of type klass. 
- 
        #min(field, klass : T.class) : T forall T
        
          Returns minimum value of the field field of type klass. 
- 
        #sum(field, klass : T.class) : T forall T
        
          Returns sum of the field field of type klass. 
Instance Method Detail
Returns average value of the field field of type klass.
field is pasted as is into the query. Also ArgumentError is raised if any grouping
is already specified.
# for MySQL
Jennifer::Query["contacts"].avg("age", Float64) # => 17.5
# for PostgreSQL
Jennifer::Query["contacts"].avg("age", PG::Numeric) # => 17.5 of PG::NumericReturns array of average values of the field field of type klass in groups.
field is pasted as is into the query.
# MySQL
Jennifer::Query["contacts"].group(:city_id).group_avg("age", Float64) # => [45.0, 39.0]
# PostgreSQL
Jennifer::Query["contacts"].group(:city_id).group_avg("age", PG::Numeric) # => [45.0, 39.0] of PG::NumericReturns array of counts values of the field field of type klass in groups.
field is pasted as is into the query.
Jennifer::Query["contacts"].group(:city_id).group_count("age", Int32) # => [45, 39]Returns array of maximum values of the field field of type klass in groups.
field is pasted as is into the query.
Jennifer::Query["contacts"].group(:city_id).group_max("age", Int32) # => [45, 39]Returns array of minimum values of the field field of type klass in groups.
field is pasted as is into the query.
Jennifer::Query["contacts"].group(:city_id).group_min("age", Int32) # => [45, 39]Returns array of values sums of the field field of type klass in groups.
field is pasted as is into the query.
# MySQL
Jennifer::Query["contacts"].group(:city_id).group_sum("age", Float64) # => [45.0, 39.0]
# PostgreSQL
Jennifer::Query["contacts"].group(:city_id).group_sum("age", Int64) # => [45, 39] of Int64Returns maximum value of the field field of type klass.
field is pasted as is into the query. Also ArgumentError is raised if any grouping
is already specified.
Jennifer::Query["contacts"].max("age", Int32) # => 45Returns minimum value of the field field of type klass.
field is pasted as is into the query. Also ArgumentError is raised if any grouping
is already specified.
Jennifer::Query["contacts"].min("age", Int32) # => 18Returns sum of the field field of type klass.
field is pasted as is into the query. Also ArgumentError is raised if any grouping
is already specified.
# for MySQL
Jennifer::Query["contacts"].sum("age", Float64) # => 1000.0
# for PostgreSQL
Jennifer::Query["contacts"].sum("age", Int64) # => 1000i64