query-d1476961cf96f54d178d79a4d909450e

rq turtle/ttl

coses de Barcelona sense barri ni districte, agrupades per instància SELECT DISTINCT ?inst ?instLabel (COUNT(DISTINCT(?item)) AS ?nitems) WHERE { ?item wdt:P31 ?inst. ?item wdt:P131+ wd:Q1492. ?item wdt:P625 ?coord. OPTIONAL { ?item wdt:P131+ ?districte. ?districte wdt:P31 wd:Q790344. } OPTIONAL { ?item wdt:P131+ ?barri. ?barri wdt:P31 wd:Q75135432. } BIND (COALESCE (?barri, ?districte) AS ?div). SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ca,en,es,fr,de" . } FILTER (!BOUND(?div)) } GROUP BY ?inst ?instLabel ORDER BY DESC(?nitems) ?instLabel

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# coses de Barcelona sense barri ni districte, agrupades per instància
SELECT DISTINCT  ?inst ?instLabel (COUNT(DISTINCT(?item)) AS ?nitems) WHERE {
  ?item wdt:P31 ?inst.
  ?item wdt:P131+ wd:Q1492.
  ?item wdt:P625 ?coord.
    OPTIONAL {
    ?item wdt:P131+ ?districte.
    ?districte wdt:P31 wd:Q790344.
  }
    OPTIONAL {
    ?item wdt:P131+ ?barri.
    ?barri wdt:P31 wd:Q75135432.
  }
  BIND (COALESCE (?barri, ?districte) AS ?div).
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ca,en,es,fr,de" . 
  }
  FILTER (!BOUND(?div))
}
GROUP BY ?inst ?instLabel
ORDER BY DESC(?nitems) ?instLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v8("?barri") v6("?coord") v7("?districte") v9("?div") v5("?inst"):::projected v2("?instLabel"):::projected v4("?item"):::projected v9("?nitems") c8(["bd:serviceParam"]):::iri c6(["wd:Q75135432"]):::iri c3(["wd:Q1492"]):::iri c5(["wd:Q790344"]):::iri c10(["#91;AUTO_LANGUAGE#93;,ca,en,es,fr,de"]):::literal f0[["not bound(?div)"]] f0 --> v9 v4 --"wdt:P31"--> v5 v4 --"wdt:P131"--> c3 v4 --"wdt:P625"--> v6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."wdt:P131".-> v7 v7 --"wdt:P31"--> c5 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."wdt:P131".-> v8 v8 --"wdt:P31"--> c6 end bind1[/"?barri?districte"/] v8 --o bind1 v7 --o bind1 bind1 --as--o v9 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end bind3[/"count(?item)"/] v4 --o bind3 bind3 --as--o v9