query-8af0f610c05a261296bb4c466253e078
Italian municipalities and population 09:02, 17 February 2023 (UTC)) talk (Loryxz2000good morning, I would need to create a query to obtain demographic data such as the population of each Italian municipality. Is this possible? Thanks. I tried this query but it timed out
Use at
- https://query.wikidata.org/sparql
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 pq: <http://www.wikidata.org/prop/qualifier/>
# Comuni d'Italia con coordinate, codice ISTAT e codice Wikidata
# Author: Valerio Bozzolan
# Date: 6 novembre 2018
# Query license: public domain
# Original query: https://gist.github.com/valerio-bozzolan/b12b0625619f257b58dabefa1474b7f4
#defaultView:Map
SELECT
( SAMPLE( ?regioneLabel ) AS ?regioneLabel )
( SAMPLE( ?provinciaLabel ) AS ?provinciaLabel )
( SAMPLE( ?comuneLabel ) AS ?comuneLabel )
( SAMPLE( ?position ) AS ?position )
( SAMPLE( ?regione ) AS ?regione )
( SAMPLE( ?provincia ) AS ?provincia )
?comune
( SAMPLE( ?regioneIstat ) AS ?regioneIstat )
( SAMPLE( ?provinciaIstat ) AS ?provinciaIstat )
( SAMPLE( ?comuneIstat ) AS ?comuneIstat )
WHERE
{
{
# i comuni italiani
?comune wdt:P31 wd:Q747074.
} UNION {
# ed in comuni "sparsi" (WTF? asd)
?comune wdt:P31 wd:Q954172.
}
# solo i comuni con codice ISTAT e posizione
?comune wdt:P635 ?comuneIstat;
wdt:P625 ?position.
# non voglio i comuni defunti
MINUS { ?comune pq:P582 ?comuneAsd }
{
# il comune e' nell'unita' amministrativa provincia
?comune wdt:P131 ?provincia.
?provincia wdt:P635 ?provinciaIstat;
wdt:P31 wd:Q15089;
wdt:P131 ?regione.
# non voglio provincie defunte
MINUS { ?provincia pq:P582 ?provinciaAsd1 }
?provincia rdfs:label ?provinciaLabel.
FILTER( LANG( ?provinciaLabel ) = "it" ).
} UNION {
# oppure il comune e' nell'unita' amministrativa citta' metropolitana
?comune wdt:P131 ?provincia.
?provincia wdt:P635 ?provinciaIstat;
wdt:P31 wd:Q15110;
wdt:P131 ?regione;
# non voglio provincie defunte
MINUS { ?provincia pq:P582 ?provinciaAsd2 }
?provincia rdfs:label ?provinciaLabel.
FILTER( LANG( ?provinciaLabel ) = "it" ).
} UNION {
# oppure il comune e' direttamente nell'unita' amministrativa regione
?comune wdt:P131 ?regione
}
?regione wdt:P635 ?regioneIstat.
# regione / regione a statuto speciale
{
?regione wdt:P31 wd:Q16110.
} UNION {
?regione wdt:P31 wd:Q1710033.
}
# il SERVICE di Wikidata mi fa paura. asd
?comune rdfs:label ?comuneLabel.
?regione rdfs:label ?regioneLabel.
FILTER( LANG( ?comuneLabel ) = "it" ).
FILTER( LANG( ?regioneLabel ) = "it" ).
}
GROUP BY ?comune
ORDER BY ?regioneLabel ?provinciaLabel ?comuneLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?comune"):::projected
v7("?comuneAsd")
v14("?comuneIstat"):::projected
v14("?comuneLabel"):::projected
v14("?position"):::projected
v14("?provincia"):::projected
v11("?provinciaAsd1")
v12("?provinciaAsd2")
v14("?provinciaIstat"):::projected
v14("?provinciaLabel"):::projected
v14("?regione"):::projected
v14("?regioneIstat"):::projected
v14("?regioneLabel"):::projected
c4(["wd:Q954172"]):::iri
c13(["wd:Q1710033"]):::iri
c12(["wd:Q16110"]):::iri
c11(["wd:Q15110"]):::iri
c9(["wd:Q15089"]):::iri
c3(["wd:Q747074"]):::iri
f0[["?regioneLabel = 'it'"]]
f0 --> v14
f1[["?comuneLabel = 'it'"]]
f1 --> v14
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P31"--> c4
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P31"--> c3
end
union0r <== or ==> union0l
end
v4 --"wdt:P635"--> v14
v4 --"wdt:P625"--> v14
subgraph minus2["MINUS"]
style minus2 stroke-width:6px,fill:pink,stroke:red;
v4 --"pq:P582"--> v7
end
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
subgraph union2[" Union "]
subgraph union2l[" "]
style union2l fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P131"--> v14
end
subgraph union2r[" "]
style union2r fill:#abf,stroke-dasharray: 3 3;
f3[["?provinciaLabel = 'it'"]]
f3 --> v14
v4 --"wdt:P131"--> v14
v14 --"wdt:P635"--> v14
v14 --"wdt:P31"--> c11
v14 --"wdt:P131"--> v14
subgraph minus4["MINUS"]
style minus4 stroke-width:6px,fill:pink,stroke:red;
v14 --"pq:P582"--> v12
end
v14 --"rdfs:label"--> v14
end
union2r <== or ==> union2l
end
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
f5[["?provinciaLabel = 'it'"]]
f5 --> v14
v4 --"wdt:P131"--> v14
v14 --"wdt:P635"--> v14
v14 --"wdt:P31"--> c9
v14 --"wdt:P131"--> v14
subgraph minus6["MINUS"]
style minus6 stroke-width:6px,fill:pink,stroke:red;
v14 --"pq:P582"--> v11
end
v14 --"rdfs:label"--> v14
end
union1r <== or ==> union1l
end
v14 --"wdt:P635"--> v14
subgraph union3[" Union "]
subgraph union3l[" "]
style union3l fill:#abf,stroke-dasharray: 3 3;
v14 --"wdt:P31"--> c13
end
subgraph union3r[" "]
style union3r fill:#abf,stroke-dasharray: 3 3;
v14 --"wdt:P31"--> c12
end
union3r <== or ==> union3l
end
v4 --"rdfs:label"--> v14
v14 --"rdfs:label"--> v14
bind16[/"sample(?regioneLabel)"/]
v14 --o bind16
bind16 --as--o v14
bind17[/"sample(?provinciaLabel)"/]
v14 --o bind17
bind17 --as--o v14
bind18[/"sample(?comuneLabel)"/]
v14 --o bind18
bind18 --as--o v14
bind19[/"sample(?position)"/]
v14 --o bind19
bind19 --as--o v14
bind20[/"sample(?regione)"/]
v14 --o bind20
bind20 --as--o v14
bind21[/"sample(?provincia)"/]
v14 --o bind21
bind21 --as--o v14
bind22[/"sample(?regioneIstat)"/]
v14 --o bind22
bind22 --as--o v14
bind23[/"sample(?provinciaIstat)"/]
v14 --o bind23
bind23 --as--o v14
bind24[/"sample(?comuneIstat)"/]
v14 --o bind24
bind24 --as--o v14