query-7f1ad658ff1cc8989fa70f306f1c9e4b

rq turtle/ttl

Number of comuni per province of a specific region (e.g. Lombardia)

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#>
#Italia: number of comuni per province of the region Lombardia
#defaultView:Table
SELECT ?provincia ?provinciaLabel (COUNT(?comune) AS ?count)
WHERE 
{
  ?provincia wdt:P131 wd:Q1210 .                 # Administrative divisions in Lombardia

  { ?provincia wdt:P31 wd:Q15089 . }             # List of provinces
  UNION
  { ?provincia wdt:P31 wd:Q15110 . }             # metropolitan cities of Italy
  UNION
  { ?provincia wdt:P31 wd:Q21190155 . }          # Liberi consorzi comunali of Sicily

  ?comune wdt:P131 ?provincia .                  # Administrative divisions in the province
  {
    ?comune wdt:P31 wd:Q747074 .                 # Italian municipality
  }
  UNION
  {
    ?comune wdt:P31 wd:Q954172 .                 # Italian sparse municipality
  } 

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?provincia ?provinciaLabel
ORDER BY DESC(?count)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?comune"):::projected v4("?count") v2("?provincia"):::projected c6(["wd:Q21190155"]):::iri c10(["bd:serviceParam"]):::iri c8(["wd:Q954172"]):::iri c5(["wd:Q15110"]):::iri c12(["#91;AUTO_LANGUAGE#93;,en"]):::literal c2(["wd:Q1210"]):::iri c4(["wd:Q15089"]):::iri c7(["wd:Q747074"]):::iri v2 --"wdt:P131"--> c2 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P31"--> c6 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P31"--> c5 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P31"--> c4 end union0r <== or ==> union0l end v3 --"wdt:P131"--> v2 subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> c8 end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P31"--> c7 end union2r <== or ==> union2l end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end bind1[/"count(?comune)"/] v3 --o bind1 bind1 --as--o v4