Map service QueryDataStatistics method

Calculates aggregate statistics for one or more fields in a layer or table.

QueryDataStatistics(string MapName, MapTableDescription MapTableDescription, StatisticsRequest StatisticsRequest, QueryFilter QueryFilter)




The name of the data frame in the map service.


Used to define a layer or a standalone table.


Used to describe a request for statistics from a map service.


An attribute or spatial query that defines the selection criteria for the layer or standalone table associated with the MapTableDescription parameter.

Return Value

A RecordSet containing the aggregated statistical results from the records of the layer or table.

If IStatisticRequest::GroupByFields is specified, statistics will be calculated separately for each unique attribute value. The output record will contain only one record if GroupByFields is not specified. If one is specified, there will be one record for each GroupByFields value.


QueryDataStatistics returns a recordset with requested statistics optionally grouped by and/or ordered by field(s) from a layer or a table. Use StatisticsRequest to define what type of statistical information you would like to get back and how you want the result be presented (e.g. sorted differently or result grouped by values from another field).

Please note that you must check MapTableInfo::SupportsStatistics before calling this function since not all layer types or source databases support this functionality.

This function honors the definition expression set to the layer or table. If you need statistics from a set of features/rows that meet a specific criterion, then you can use QueryFilter::WhereClause and pass this as a parameter to the function. When the QueryFilter parameter is null, all features/rows are used (provided a defintion expression is not set to the table or layer) to compute statistics.

When StatisticDescriptions::ResultFieldName is not specified, an auto-generated field name will be used.


This function only works with numeric fields.



//Sample code shows getting maximum value from LANDVAL field

StatisticDescription pStatDesc = new StatisticDescription() 
	StatisticType = esriDataStatType.esriDataStatTypeMax,
	StatisticFieldName = "LANDVAL",
	ResultFieldName = "max_landval"

StatisticDescription[] pStatDescs = new StatisticDescription[1];
pStatDescs[0] = pStatDesc;
StatisticsRequest pStatReq = new StatisticsRequest();
pStatReq.StatisticDescriptions = pStatDescs;
RecordSet pRS = pMapServer.QueryDataStatistics(pMapServer.GetDefaultMapName(), m_pMapTableDescription, pStatReq, null);