query-242967cf0fa6c6598964e2b16a04313e

rq turtle/ttl

Home Secretaries, by how far through their career they were when appointed

cutoff in 2010 as this means they've all now retired

calculation does not take account of breaks in service

select distinct ?person ?personLabel ?appointed ?first_MP ?last_MP (?last_MP - ?first_MP as ?career_in_days) (?appointed - ?first_MP as ?experience_when_appointed) (round((?experience_when_appointed / ?career_in_days)*100) as ?percent_career) where { { select ?person ?appointed where { ?person p:P39 ?hs . ?hs ps:P39 wd:Q2484309 . ?hs pq:P580 ?appointed . filter (?appointed > "1860-01-01T00:00:00Z"^^xsd:dateTime) . filter (?appointed < "2010-01-01T00:00:00Z"^^xsd:dateTime) } }
{ select ?person (min(?s) as ?first_MP) (max(?e) as ?last_MP) where { ?person p:P39 ?ps . ?ps ps:P39 ?term . ?term wdt:P279 wd:Q16707842 . ?ps pq:P580 ?s . ?ps pq:P582 ?e } group by ?person } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } order by (?percent_career)

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#>
# Home Secretaries, by how far through their career they were when appointed
# cutoff in 2010 as this means they've all now retired
# calculation does not take account of breaks in service

select distinct ?person ?personLabel ?appointed ?first_MP ?last_MP
(?last_MP - ?first_MP as ?career_in_days)
(?appointed - ?first_MP as ?experience_when_appointed)
(round((?experience_when_appointed / ?career_in_days)*100) as ?percent_career)
where
{
  { select ?person ?appointed where 
    { ?person p:P39 ?hs . ?hs ps:P39 wd:Q2484309 . ?hs pq:P580 ?appointed . 
     filter (?appointed > "1860-01-01T00:00:00Z"^^xsd:dateTime) . filter (?appointed < "2010-01-01T00:00:00Z"^^xsd:dateTime) }
   }  
  { select ?person (min(?s) as ?first_MP) (max(?e) as ?last_MP) where 
    { ?person p:P39 ?ps . ?ps ps:P39 ?term . ?term wdt:P279 wd:Q16707842 . 
      ?ps pq:P580 ?s . ?ps pq:P582 ?e } group by ?person
   } 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} order by (?percent_career)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?appointed"):::projected v11("?career_in_days"):::projected v8("?e") v12("?experience_when_appointed"):::projected v9("?first_MP"):::projected v4("?hs") v10("?last_MP"):::projected v13("?percent_career") v3("?person"):::projected v5("?ps") v7("?s") v6("?term") c5(["wd:Q2484309"]):::iri c8(["wd:Q16707842"]):::iri c11(["bd:serviceParam"]):::iri c13(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["?appointed < '2010-01-01T00:00:00Z^^xsd:dateTime'"]] f0 --> v2 f1[["?appointed > '1860-01-01T00:00:00Z^^xsd:dateTime'"]] f1 --> v2 v3 --"p:P39"--> v4 v4 --"p:statement/P39"--> c5 v4 --"p:qualifier/P580"--> v2 v3 --"p:P39"--> v5 v5 --"p:statement/P39"--> v6 v6 --"p:direct/P279"--> c8 v5 --"p:qualifier/P580"--> v7 v5 --"p:qualifier/P582"--> v8 bind4[/"min(?s)"/] v7 --o bind4 bind4 --as--o v9 bind5[/"max(?e)"/] v8 --o bind5 bind5 --as--o v10 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 end bind6[/"?last_MP - ?first_MP"/] v10 --o bind6 v9 --o bind6 bind6 --as--o v11 bind7[/"?appointed - ?first_MP"/] v2 --o bind7 v9 --o bind7 bind7 --as--o v12 bind8[/"numeric-round(?experience_when_appointed / ?career_in_days * '100^^xsd:integer')"/] v12 --o bind8 v11 --o bind8 bind8 --as--o v13