query-80141bc6826f15030c252f6d194f8d89

rq turtle/ttl

Propertiesinstance of (P31)office held by head of government (P1313)position held (P39)start time (P580)end time (P582)

Use at

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#>
#defaultView:BarChart
SELECT ?person ?personLabel (xsd:integer(FLOOR(SUM(DISTINCT ?end-?start)/365.2425)) AS ?totalYears) WHERE {
  ?person wdt:P31 wd:Q5;
          p:P39 [
            ps:P39/^wdt:P1313 wd:Q668;
            pq:P580 ?start;
            pq:P582 ?end
          ].
  BIND(xsd:integer(FLOOR((?end-?start)/365.2425)) AS ?years).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "it", "en". }
}
GROUP BY ?person ?personLabel
ORDER BY DESC(?totalYears)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?end") v2("?person"):::projected v3("?start") v6("?totalYears") v5("?years") a1((" ")) a2((" ")) c13(["en"]):::literal c12(["it"]):::literal c10(["bd:serviceParam"]):::iri c4(["wd:Q668"]):::iri c2(["wd:Q5"]):::iri v2 --"p:direct/P31"--> c2 a1 --"p:statement/P39"--> a2 c4 --"p:direct/P1313"--> a2 a1 --"p:qualifier/P580"--> v3 a1 --"p:qualifier/P582"--> v4 v2 --"p:P39"--> a1 bind0[/"http://www.w3.org/2001/XMLSchema#integer(numeric-floor(?end - ?start / '365.2425^^xsd:decimal'))"/] v4 --o bind0 v3 --o bind0 bind0 --as--o v5 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 c10 --"wikibase:language"--> c13 end bind2[/"http://www.w3.org/2001/XMLSchema#integer(numeric-floor( / '365.2425^^xsd:decimal'))"/] null --o bind2 bind2 --as--o v6