NotoDB supports SQL-like aggregate functions. Use the query method to leverage aggregate functions in your application.
The following is the basic syntax of a query request with an aggregate function.
[
{
"{aggregation}": "{field to aggregate or * (all)}"
}
][
{
"_1": "{int result}"
}
]In the following example we are going to return the average age of all users who live in Oakland, CA.
[
{
"avg": "age"
}
][
{
"_1": 42
}
]In the following example we are going to return the total count and average age of all users who live in Oakland, CA.
[
{
"count": "*"
},
{
"avg": "age"
}
][
{
"_1": 379,
"_2": 42
}
]Note that the response return contains keys such as _1, _2, _3, etc. These are in the order in which the aggregations are sent. In the above example, _1 is the total count, whereas _2 is the average age.
To return the total count of all items in a set, or run an aggregation across all items in a set without any query parameters, consider the following example:
[
{
"count": "*"
}
][
{
"_1": 23452
}
]Available functions
| Aggregate function | Example |
|---|---|
| COUNT | {"count":"*"} |
| AVG | {"avg":"age"} |
| SUM | {"sum":"transaction_amount"} |
| MIN | {"min":"age"} |
| MAX | {"max":"age"} |
See Querying items for more information on querying items in a set.
Next articleUpdating items