---
title: HKStatisticsCollectionQuery
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkstatisticscollectionquery
---

# HKStatisticsCollectionQuery

A query that performs multiple statistics queries over a series of fixed-length time intervals.

## Declaration

```swift
class HKStatisticsCollectionQuery
```

## Mentioned in

Accessing condensed workout samples Executing Statistics Collection Queries

## Overview

Overview Statistics collection queries are often used to produce data for graphs and charts. For example, you might create a statistics collection query that calculates the total number of steps for each day or the average heart rate for each hour. Like observer queries, collection queries can also act as long-running queries, receiving updates when the HealthKit store’s content changes. important: You can only use statistics collection queries with quantity samples. If you want to calculate statistics over workouts or correlation samples, you must perform the appropriate query and process the data yourself. Statistics collection queries are mostly immutable. You can assign the query’s initialResultsHandler and statisticsUpdateHandler properties after instantiating the object. You must set all other properties when you instantiate the object, and they can’t change. For more information about statistics queries, see HKStatisticsQuery.

## Topics

### Creating Statistics Collection Objects

- [Executing Statistics Collection Queries](healthkit/executing-statistics-collection-queries.md)
- [init(quantityType:quantitySamplePredicate:options:anchorDate:intervalComponents:)](healthkit/hkstatisticscollectionquery/init(quantitytype:quantitysamplepredicate:options:anchordate:intervalcomponents:).md)

### Getting and Setting Results Handlers

- [initialResultsHandler](healthkit/hkstatisticscollectionquery/initialresultshandler.md)
- [statisticsUpdateHandler](healthkit/hkstatisticscollectionquery/statisticsupdatehandler.md)

### Getting Property Data

- [anchorDate](healthkit/hkstatisticscollectionquery/anchordate.md)
- [intervalComponents](healthkit/hkstatisticscollectionquery/intervalcomponents.md)
- [options](healthkit/hkstatisticscollectionquery/options.md)

## Relationships

### Inherits From

- [HKQuery](healthkit/hkquery.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Statistics

- [Executing Statistical Queries](healthkit/executing-statistical-queries.md)
- [Executing Statistics Collection Queries](healthkit/executing-statistics-collection-queries.md)
- [HKStatisticsQueryDescriptor](healthkit/hkstatisticsquerydescriptor.md)
- [HKStatisticsQuery](healthkit/hkstatisticsquery.md)
- [HKStatisticsCollectionQueryDescriptor](healthkit/hkstatisticscollectionquerydescriptor.md)
- [HKStatistics](healthkit/hkstatistics.md)
- [HKStatisticsCollection](healthkit/hkstatisticscollection.md)
- [HKStatisticsOptions](healthkit/hkstatisticsoptions.md)
