---
title: HKStatisticsQuery
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkstatisticsquery
---

# HKStatisticsQuery

A query that performs statistical calculations over a set of matching quantity samples, and returns the results.

## Declaration

```swift
class HKStatisticsQuery
```

## Mentioned in

Accessing condensed workout samples Executing Statistics Collection Queries

## Overview

Overview Statistics queries calculate common statistics over the set of matching samples. You can use statistical queries to calculate the minimum, maximum, or average value of a set of discrete quantities, or use them to calculate the sum for cumulative quantities. For the complete list of possible calculations, see HKStatisticsOptions. For more information about the available quantity types and to learn whether they are discrete or cumulative values, see Data types. You can use statistics queries with quantity samples only. If you want to calculate statistics over workouts or correlation samples, you must perform the appropriate query and process the data yourself. Statistics queries are immutable. Their properties are set when they are first created, and they can’t change.

## Topics

### Creating Statistics Queries

- [init(quantityType:quantitySamplePredicate:options:completionHandler:)](healthkit/hkstatisticsquery/init(quantitytype:quantitysamplepredicate:options:completionhandler:).md)
- [Executing Statistical Queries](healthkit/executing-statistical-queries.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)
- [HKStatisticsCollectionQueryDescriptor](healthkit/hkstatisticscollectionquerydescriptor.md)
- [HKStatisticsCollectionQuery](healthkit/hkstatisticscollectionquery.md)
- [HKStatistics](healthkit/hkstatistics.md)
- [HKStatisticsCollection](healthkit/hkstatisticscollection.md)
- [HKStatisticsOptions](healthkit/hkstatisticsoptions.md)
