query-5612ea735968118e38ba8447e7b41bb0

rq turtle/ttl

56 member states of the Commonwealth of Nations

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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX v: <http://www.wikidata.org/prop/statement/>
SELECT ?state ?code ?stateLabel (GROUP_CONCAT(DISTINCT(?capitalName);separator="; ") AS ?capitals) (GROUP_CONCAT(DISTINCT(?continentName);separator="; ") AS ?continents) ?start WHERE {
  ?state p:P463 ?memberBlock . 
  ?memberBlock v:P463 wd:Q7785 .
  ?memberBlock pq:P580 ?start .
  #?memberBlock pq:P582 ?end .
  FILTER NOT EXISTS {?memberBlock pq:P582 ?end} .
  ?state wdt:P36 ?capital . ?capital rdfs:label ?capitalName . FILTER(lang(?capitalName) = "en") .
  ?state wdt:P30 ?continent . ?continent rdfs:label ?continentName . FILTER(lang(?continentName) = "en") .
  OPTIONAL{?state wdt:P298 ?code}
  SERVICE wikibase:label{bd:serviceParam wikibase:language "en"}
}
GROUP BY ?state ?stateLabel ?start ?code
ORDER BY ?continents ?code

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v9("?capital") v4("?capitalName"):::projected v11("?capitals") v2("?code"):::projected v10("?continent") v3("?continentName"):::projected v12("?continents") v6("?end") v5("?memberBlock") v8("?start"):::projected v7("?state"):::projected c1(["en"]):::literal c12(["bd:serviceParam"]):::iri c5(["wd:Q7785"]):::iri f0[["?continentName = 'en'"]] f0 --> v3 f1[["?capitalName = 'en'"]] f1 --> v4 f2[["not "]] subgraph f2e0["Exists Clause"] e0v1 --"p:qualifier/P582"--> e0v2 e0v2("?end"):::projected e0v1("?memberBlock"):::projected end f2--EXISTS--> f2e0 f2 --> v5 f2 --> c2 f2 --> v6 v5 --"p:qualifier/P582"--> v6 v7 --"p:P463"--> v5 v5 --"p:statement/P463"--> c5 v5 --"p:qualifier/P580"--> v8 v7 --"p:direct/P36"--> v9 v9 --"rdfs:label"--> v4 v7 --"p:direct/P30"--> v10 v10 --"rdfs:label"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v7 -."p:direct/P298".-> v2 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c12 --"wikibase:language"--> c1 end bind5[/"?capitalName"/] v4 --o bind5 bind5 --as--o v11 bind6[/"?continentName"/] v3 --o bind6 bind6 --as--o v12