Aggregation, grouping and summarizing
Teo allows you to count records, aggregate number fields with or without grouping, and select distinct field values.
Count
Use count
to count the number of records. The following example returns the
number of artists in the database:
Filtered count
count
can be filtered and paginated.
Aggregate
Teo allows you to aggregate on the number fields of a model. The following query returns the average age of all artists:
Aggregate uses non null values to calculate avg
and sum
. If all values from
records on a field are null, the aggregated value is also null.
Group by
Teo allows you to group aggregated values by some field values. The following example groups all artists by the name field and returns the average age for artists under each name:
Filter group results with having
groupBy
results can be filtered with having
. having
is different than
where
. where
filters on records, while having
filters on aggregation
results.
Distinct values
Teo allows you to remove duplicate records on some fields. distinct
is often
used with select
to identify certain unique combinations of values in the
rows of your table.