← Expressions
Review string, date, and math functions.
Go BackAnalyze and summarize your data with powerful aggregate functions. Count items, calculate averages, find extremes, and group results for insightful analytics.
Aggregate functions transform multiple rows of data into summary statistics. Instead of listing every programming language, you can count them, find the oldest, calculate average ages, or group them by paradigm.
Combined with GROUP BY and HAVING, aggregates turn SPARQL
into a powerful tool for data analysis and insight generation.
Count the number of matching results or distinct values.
BeginnerCalculate the total of numeric values across results.
IntermediateCompute the average of numeric values.
IntermediateFind the smallest value in a set of results.
BeginnerFind the largest value in a set of results.
BeginnerSelect an arbitrary value from a group.
IntermediateGroup results by one or more variables for aggregation.
IntermediateFilter groups based on aggregate conditions.
IntermediateCombine multiple values into a single concatenated string.
IntermediateSELECT (COUNT(?lang) AS ?total)
WHERE {
?lang wdt:P31 wd:Q9143 .
}
SELECT ?paradigmLabel (COUNT(?lang) AS ?count)
WHERE {
?lang wdt:P31 wd:Q9143 ;
wdt:P3966 ?paradigm .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
GROUP BY ?paradigmLabel
ORDER BY DESC(?count)
LIMIT 10
SELECT ?paradigmLabel (COUNT(?lang) AS ?count)
WHERE {
?lang wdt:P31 wd:Q9143 ;
wdt:P3966 ?paradigm .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
GROUP BY ?paradigmLabel
HAVING (?count > 5)
ORDER BY DESC(?count)
| Function | Description | Example |
|---|---|---|
COUNT(?var) |
Count number of values | COUNT(?item) |
COUNT(DISTINCT ?var) |
Count unique values | COUNT(DISTINCT ?type) |
SUM(?var) |
Sum of numeric values | SUM(?population) |
AVG(?var) |
Average of numeric values | AVG(?age) |
MIN(?var) |
Minimum value | MIN(?date) |
MAX(?var) |
Maximum value | MAX(?date) |
SAMPLE(?var) |
Arbitrary value from group | SAMPLE(?image) |
GROUP_CONCAT(?var; separator=",") |
Concatenate values | GROUP_CONCAT(?name; separator=", ") |