query-9e146e13dc4b49a8585c9fd111c028aa

rq turtle/ttl

SPARQL query

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#>
SELECT DISTINCT ?id (STRAFTER(STR(?item), STR(wd:)) AS ?wikidata_id)
WHERE {
  ?item p:P39 ?mem .
  ?mem ps:P39 wd:Q13217683 .
  OPTIONAL { ?item wdt:P1157 ?id }
  OPTIONAL { ?mem pq:P580 ?startDate }
  OPTIONAL { ?mem pq:P582 ?endDate }
  FILTER (
    (BOUND(?startDate) && (?startDate >= "2017-01-03T00:00:00Z"^^xsd:dateTime)) ||
    (BOUND(?endDate) && (?endDate > "2017-01-03T00:00:00Z"^^xsd:dateTime)) ||
    (BOUND(?startDate) && !BOUND(?endDate))
  ).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} ORDER BY ?id

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?endDate") v1("?id"):::projected v4("?item"):::projected v5("?mem") v2("?startDate") v6("?wikidata_id") c9(["bd:serviceParam"]):::iri c4(["wd:Q13217683"]):::iri c11(["en"]):::literal f0[["(bound(?startDate)?startDate >= '2017-01-03T00:00:00Z^^xsd:dateTime' || (bound(?endDate)?endDate > '2017-01-03T00:00:00Z^^xsd:dateTime' || bound(?startDate)not bound(?endDate)))"]] f0 --> v2 f0 --> v3 v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> c4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P1157".-> v1 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:qualifier/P580".-> v2 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:qualifier/P582".-> v3 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end bind1[/"substring-after(str(?item),str('wd:'))"/] v4 --o bind1 bind1 --as--o v6