query-f9f97bf2e17942409ebd0de601fffdb6
TODO
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?person ?personLabel (xsd:integer(FLOOR(SUM(DISTINCT ?end-?start)/365.2425)) AS ?totalYears) (COUNT(DISTINCT ?stsq) AS ?count) WHERE {
?person wdt:P31 wd:Q5;
p:P39 [
ps:P39/^wdt:P1313 wd:Q38;
pq:P580 ?start;
pq:P582 ?end
].
BIND(xsd:integer(FLOOR((?end-?start)/365.2425)) AS ?years).
OPTIONAL {
?stsq wdt:P31/wdt:P279* wd:Q83620;
wdt:P131+ wd:Q18288155; # or Q490 for just the city
wdt:P138 ?person.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "it", "en". }
}
GROUP BY ?person ?personLabel
ORDER BY DESC(?totalYears) DESC(?count)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?count")
v5("?end")
v3("?person"):::projected
v4("?start")
v7("?stsq"):::projected
v8("?totalYears")
v6("?years")
a1((" "))
a2((" "))
a3((" "))
c12(["wd:Q18288155"]):::iri
c18(["en"]):::literal
c17(["it"]):::literal
c4(["wd:Q38"]):::iri
c15(["bd:serviceParam"]):::iri
c10(["wd:Q83620"]):::iri
c2(["wd:Q5"]):::iri
v3 --"p:direct/P31"--> c2
a1 --"p:statement/P39"--> a2
c4 --"p:direct/P1313"--> a2
a1 --"p:qualifier/P580"--> v4
a1 --"p:qualifier/P582"--> v5
v3 --"p:P39"--> a1
bind0[/"http://www.w3.org/2001/XMLSchema#integer(numeric-floor(?end - ?start / '365.2425^^xsd:decimal'))"/]
v5 --o bind0
v4 --o bind0
bind0 --as--o v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:direct/P31".-> a3
a3 --"p:direct/P279"--> c10
v7 --"p:direct/P131"--> c12
v7 --"p:direct/P138"--> v3
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c15 --"wikibase:language"--> c17
c15 --"wikibase:language"--> c18
end
bind3[/"http://www.w3.org/2001/XMLSchema#integer(numeric-floor( / '365.2425^^xsd:decimal'))"/]
null --o bind3
bind3 --as--o v8
bind4[/"count(?stsq)"/]
v7 --o bind4
bind4 --as--o v8