query-06db37689c032eb72b374dc834be8207

rq turtle/ttl

The next query reports the number of comuni per region:

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#Italia: number of comuni per region
#defaultView:Table
SELECT ?regione ?regioneLabel (COUNT(?comune) AS ?count)
WHERE 
{
  ?regione p:P31/ps:P31/wdt:P279* wd:Q16110 .    # Regions of Italia
  ?provincia wdt:P131 ?regione .                 # Administrative divisions in the region

  { ?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 ?regione ?regioneLabel
ORDER BY DESC(?count)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?comune"):::projected v5("?count") v3("?provincia") v2("?regione"):::projected a1((" ")) a2((" ")) c11(["wd:Q954172"]):::iri c9(["wd:Q21190155"]):::iri c13(["bd:serviceParam"]):::iri c4(["wd:Q16110"]):::iri c8(["wd:Q15110"]):::iri c15(["#91;AUTO_LANGUAGE#93;,en"]):::literal c7(["wd:Q15089"]):::iri c10(["wd:Q747074"]):::iri v2 --"p:P31"--> a1 a1 --"p:statement/P31"--> a2 a2 --"p:direct/P279"--> c4 v3 --"p:direct/P131"--> v2 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; v3 --"p:direct/P31"--> c9 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P31"--> c8 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P31"--> c7 end union0r <== or ==> union0l end v4 --"p:direct/P131"--> v3 subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P31"--> c11 end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P31"--> c10 end union2r <== or ==> union2l end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c13 --"wikibase:language"--> c15 end bind1[/"count(?comune)"/] v4 --o bind1 bind1 --as--o v5