query-904031e5aed31c48aab669703a31b5f1
MIN/MAX ordered by other columnThis has tons of uses. For instance, here’s the population of largest city per country:
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?country (MAX(?population) AS ?maxPopulation) WHERE {
?city wdt:P31/wdt:P279* wd:Q515;
wdt:P1082 ?population;
wdt:P17 ?country.
}
GROUP BY ?country
ORDER BY DESC(?maxPopulation)
LIMIT 10
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?city")
v4("?country"):::projected
v5("?maxPopulation")
v3("?population"):::projected
a1((" "))
c3(["wd:Q515"]):::iri
v2 --"wdt:P31"--> a1
a1 --"wdt:P279"--> c3
v2 --"wdt:P1082"--> v3
v2 --"wdt:P17"--> v4
bind1[/"max(?population)"/]
v3 --o bind1
bind1 --as--o v5