query-bad18998d47aea4f6cf52229ee81c14b
Find all mineral type localities and sort them by most minerals defined SELECT ?locality ?name (COUNT(DISTINCT ?mineral) AS ?count) WHERE { ?mineral wdt:P279* wd:Q7946 . # Find all instances and subclasses of mineral (traverse the tree) ?mineral wdt:P2695 ?locality . # Where a locality statement exists
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
?locality rdfs:label ?name
}
} GROUP BY ?locality ?name ORDER BY DESC(?count)
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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Find all mineral type localities and sort them by most minerals defined
SELECT ?locality ?name (COUNT(DISTINCT ?mineral) AS ?count)
WHERE
{
?mineral wdt:P279* wd:Q7946 . # Find all instances and subclasses of mineral (traverse the tree)
?mineral wdt:P2695 ?locality . # Where a locality statement exists
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
?locality rdfs:label ?name
}
}
GROUP BY ?locality ?name
ORDER BY DESC(?count)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?count")
v3("?locality"):::projected
v2("?mineral"):::projected
v4("?name"):::projected
c5(["bd:serviceParam"]):::iri
c7(["en"]):::literal
c2(["wd:Q7946"]):::iri
v2 --"wdt:P279"--> c2
v2 --"wdt:P2695"--> v3
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c5 --"wikibase:language"--> c7
v3 --"rdfs:label"--> v4
end
bind1[/"count(?mineral)"/]
v2 --o bind1
bind1 --as--o v5