A query that performs statistical calculations over a set of matching quantity samples, and returns the results.
- iOS 8.0+
- Mac Catalyst 13.0+
- watchOS 2.0+
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
HKStatistics. 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.