query-7293a5eafcd150e610d94dbd39f3e865
Obtaining Wikidata statistics for items related to geography
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?geography ?geographyLabel ?class1 ?class1Label (COUNT(DISTINCT ?class) AS ?classes) (MIN(?instances) AS ?min) (MAX(?instances) AS ?max) (SUM(?instances) AS ?sum) WHERE {
{
SELECT DISTINCT ?geography ?class1 ?class (COUNT(DISTINCT ?instance) AS ?instances) WHERE {
VALUES ?geography {wd:Q4006}
#VALUES ?geography {wd:Q8008} # wd:Q2221906 wd:Q2625603 wd:Q27096213}
OPTIONAL {?class1 wdt:P279 ?geography.
?subclass wdt:P279* ?class1.}
BIND(COALESCE(?subclass, ?geography) AS ?class)
OPTIONAL {?class ?property ?value.}
#?property rdf:type owl:DatatypeProperty.
OPTIONAL {?instance wdt:P31 ?class.}
}
GROUP BY ?geography ?class1 ?class
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?geography ?geographyLabel ?class1 ?class1Label
ORDER BY CONCAT(STR(?geography), " ", IF(BOUND(?class1), STR(?class1Label), " "))
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?class"):::projected
v2("?class1"):::projected
v3("?class1Label"):::projected
v10("?classes")
v4("?geography"):::projected
v8("?instance")
v9("?instances"):::projected
v12("?max")
v11("?min")
v6("?property")
v4("?subclass")
v13("?sum")
v7("?value")
c6(["bd:serviceParam"]):::iri
c8(["en"]):::literal
bind0[/VALUES ?geography/]
bind0-->v4
bind00(["wd:Q4006"])
bind00 --> bind0
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."wdt:P279".-> v4
v4 --"wdt:P279"--> v2
end
bind1[/"?subclass?geography"/]
v4 --o bind1
v4 --o bind1
bind1 --as--o v5
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v5 -->v6--> v7
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v8 -."wdt:P31".-> v5
end
bind3[/"count(?instance)"/]
v8 --o bind3
bind3 --as--o v9
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c6 --"wikibase:language"--> c8
end
bind8[/"count(?class)"/]
v5 --o bind8
bind8 --as--o v10
bind9[/"min(?instances)"/]
v9 --o bind9
bind9 --as--o v11
bind10[/"max(?instances)"/]
v9 --o bind10
bind10 --as--o v12
bind11[/"sum(?instances)"/]
v9 --o bind11
bind11 --as--o v13