query-fe88e072649cab72f3dc2a446a5b7938

rq turtle/ttl

title: UK Health Ministers and their occupations on Wikidata SELECT ?x ?xLabel ?start (GROUP_CONCAT(?occLabel ;separator="; ") as ?occupations) WITH {

SELECT DISTINCT ?x (SAMPLE(?start) AS ?start) WHERE { # Using sample as ministers may have held the position multiple times but we're only interested in one ?x wdt:P31 wd:Q5 . ?x p:P39 ?node . ?node ps:P39 ?position ; pq:P580 ?start . ?position wdt:P361 wd:Q112014 . # member of the UK Cabinet ?position wdt:P279 wd:Q3273722 . # health minister } GROUP BY ?x } AS %health_ministers WHERE { INCLUDE %health_ministers OPTIONAL {?x wdt:P106 ?occ . ?occ rdfs:label ?occLabel. FILTER (LANG(?occLabel) = "en") } BIND(COALESCE(?occLabel, "None") AS ?occLabel ) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } GROUP BY ?x ?xLabel ?start ORDER BY DESC (?start)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
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 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#>
#title: UK Health Ministers and their occupations on Wikidata
SELECT ?x ?xLabel ?start (GROUP_CONCAT(?occLabel ;separator="; ") as ?occupations)  WHERE {
   {

SELECT DISTINCT ?x (SAMPLE(?start) AS ?start) WHERE {  # Using sample as ministers may have held the position multiple times but we're only interested in one
  ?x wdt:P31 wd:Q5 .
  ?x p:P39 ?node .
  ?node ps:P39 ?position ;
        pq:P580 ?start .
  ?position wdt:P361 wd:Q112014 .   # member of the UK Cabinet
  ?position wdt:P279 wd:Q3273722 .  # health minister
} GROUP BY ?x }  OPTIONAL {?x wdt:P106 ?occ . ?occ rdfs:label ?occLabel.   FILTER (LANG(?occLabel) = "en") }
  BIND(COALESCE(?occLabel, "None") AS ?occLabel )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?x ?xLabel ?start
ORDER BY DESC (?start)

Query found at