module
Lustra::SQL::Query::Aggregate
Direct including types
Defined in:
lustra/sql/query/aggregate.crInstance Method Summary
-
#agg(field, x : X.class) forall X
Call an custom aggregation function, like MEDIAN or other:
-
#avg(field, x : X.class) forall X
SQL aggregation function "AVG":
-
#count(type : X.class = Int64) forall X
Use SQL
COUNT
over your query, and return this number as a Int64 -
#exists? : Bool
Check if any records exist matching the query conditions.
-
#max(field, x : X.class) forall X
SQL aggregation function "MAX":
-
#min(field, x : X.class) forall X
SQL aggregation function "MIN":
-
#sum(field) : Float64
SUM through a field and return a Float64 Note: This function is not safe injection-wise, so beware !.
Instance Method Detail
Call an custom aggregation function, like MEDIAN or other:
query.agg("MEDIAN(age)", Int64)
Note than COUNT, MIN, MAX, SUM and AVG are already conveniently mapped.
This return only one row, and should not be used with group_by
(prefer pluck or fetch)
SQL aggregation function "AVG":
query.avg("field", Int64)
Use SQL COUNT
over your query, and return this number as a Int64
as count return always a scalar, the usage of COUNT(*) OVER GROUP BY
can be done by
using pluck
or select
Check if any records exist matching the query conditions.
Returns true
if at least one record exists, false
otherwise.
User.query.where { active == true }.exists? # => true/false
SQL aggregation function "MAX":
query.max("field", Int64)
SQL aggregation function "MIN":
query.min("field", Int64)
SUM through a field and return a Float64 Note: This function is not safe injection-wise, so beware !.