query-a4bca1a6636f46bd8ece38179100e91a

rq turtle/ttl

Andrew Gray

ambassadors to Argentina

who were also MPs

SELECT DISTINCT ?item ?itemLabel ?startyear ?endyear { ?item p:P39 ?positionStatement . ?positionStatement ps:P39 wd:Q29898729 . # ambassador to Argentina OPTIONAL { ?positionStatement pq:P580 ?start . bind(year(?start) as ?startyear) . } OPTIONAL { ?positionStatement pq:P582 ?end . bind(year(?end) as ?endyear) . } ?item p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 [wdt:P279* wd:Q16707842] . # also an MP SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' } } ORDER BY desc(?startyear)

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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#Andrew Gray
# ambassadors to Argentina
# who were also MPs
SELECT DISTINCT ?item ?itemLabel ?startyear ?endyear {
 ?item p:P39 ?positionStatement . ?positionStatement ps:P39 wd:Q29898729 .  # ambassador to Argentina
 OPTIONAL { ?positionStatement pq:P580 ?start . bind(year(?start) as ?startyear) . }
 OPTIONAL { ?positionStatement pq:P582 ?end . bind(year(?end) as ?endyear) . }
  ?item p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 [wdt:P279* wd:Q16707842] . # also an MP
 SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
ORDER BY desc(?startyear)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?end") v6("?endyear"):::projected v2("?item"):::projected v3("?positionStatement") v7("?positionStatement2") v4("?start") v5("?startyear"):::projected a1((" ")) c3(["wd:Q29898729"]):::iri c9(["bd:serviceParam"]):::iri c7(["wd:Q16707842"]):::iri c11(["en"]):::literal v2 --"p:P39"--> v3 v3 --"p:statement/P39"--> c3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P580".-> v4 bind0[/"year-from-dateTime(?start)"/] v4 --o bind0 bind0 --as--o v5 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P582".-> v5 bind1[/"year-from-dateTime(?end)"/] v5 --o bind1 bind1 --as--o v6 end v2 --"p:P39"--> v7 a1 --"p:direct/P279"--> c7 v7 --"p:statement/P39"--> a1 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end