query-625426dfacb135b436cf99fb056968ce

rq turtle/ttl

Find all mineral type localities that are meteorites and sort them by defined minerals SELECT ?locality ?name (COUNT(DISTINCT ?mineral) AS ?count) WHERE { ?mineral wdt:P579 ?status . ?mineral wdt:P2695 ?locality . # Where a locality statement exists ?locality wdt:P31 ?thing . # Where the locality is the instance of a thing (helper) ?thing wdt:279* wd:Q60186 . # And the thing is in the subclass tree of meteorite (Should also work if p31 = iron meteorite for example)

SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
    ?locality rdfs:label ?name
}

} GROUP BY ?locality ?name ORDER BY DESC(?count)

Use at

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 that are meteorites and sort them by defined minerals
SELECT ?locality ?name (COUNT(DISTINCT ?mineral) AS ?count)
WHERE
{
    ?mineral wdt:P579 ?status .
    ?mineral wdt:P2695 ?locality .    # Where a locality statement exists
    ?locality wdt:P31 ?thing .        # Where the locality is the instance of a thing (helper)
    ?thing wdt:279* wd:Q60186 .       # And the thing is in the subclass tree of meteorite (Should also work if p31 = iron meteorite for example)

    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; v7("?count") v4("?locality"):::projected v2("?mineral"):::projected v6("?name"):::projected v3("?status") v5("?thing") c7(["bd:serviceParam"]):::iri c5(["wd:Q60186"]):::iri c9(["en"]):::literal v2 --"wdt:P579"--> v3 v2 --"wdt:P2695"--> v4 v4 --"wdt:P31"--> v5 v5 --"wdt:279"--> c5 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c7 --"wikibase:language"--> c9 v4 --"rdfs:label"--> v6 end bind1[/"count(?mineral)"/] v2 --o bind1 bind1 --as--o v7