Aggregate

AVG

Calculate average values. AVG computes the arithmetic mean of numeric values, useful for finding typical values in datasets.

Understanding AVG

AVG calculates the arithmetic mean (sum divided by count) of numeric values. It ignores null values and works with GROUP BY for per-category averages.

Basic AVG Examples

Average Country Population
Run ↗
SELECT (AVG(?population) AS ?avgPopulation)
WHERE {
  ?country wdt:P31 wd:Q6256 ;
           wdt:P1082 ?population .
}
Average Mountain Elevation
Run ↗
SELECT (AVG(?elevation) AS ?avgElevation)
WHERE {
  ?mountain wdt:P31 wd:Q8502 ;
            wdt:P2044 ?elevation .
}

AVG with GROUP BY

Average City Population per Country
Run ↗
SELECT ?country ?countryLabel (AVG(?population) AS ?avgCityPop)
WHERE {
  ?city wdt:P31 wd:Q515 ;
        wdt:P17 ?country ;
        wdt:P1082 ?population .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?country ?countryLabel
ORDER BY DESC(?avgCityPop)
LIMIT 10