Skip to main content

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​

  1. Use aggregates instead of fetching all nodes
  2. Combine with filters for targeted statistics
  3. Include in paginated queries for total counts