Aggregations
Compute statistical aggregations without fetching all nodes.
Query Structureβ
query GetPositionStatistics($accountId: String!) {
positions_aggregate(
where: { account_id: { _eq: $accountId } }
) {
aggregate {
count
sum { shares }
avg { shares }
min { shares }
max { shares }
stddev { shares }
variance { shares }
}
}
}
Available Functionsβ
- count: Total number of rows
- sum: Sum of values
- avg: Average value
- min: Minimum value
- max: Maximum value
- stddev: Standard deviation
- variance: Variance
- stddev_pop: Population standard deviation
- stddev_samp: Sample standard deviation
- var_pop: Population variance
- var_samp: Sample variance
Best Practicesβ
- Use aggregates instead of fetching all nodes
- Combine with filters for targeted statistics
- Include in paginated queries for total counts