query-68d969e8f4f613640c21fb82c15dafbc
50 US states with border states
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?state ?iso ?stateLabel (GROUP_CONCAT(DISTINCT(?borderIso);separator=", ") AS ?borderStates) (COUNT(?borderState) AS ?count) WHERE {
?state wdt:P31 wd:Q35657 . ?state wdt:P300 ?iso .
OPTIONAL{?state wdt:P47 ?borderState . ?borderState wdt:P31 wd:Q35657 . ?borderState wdt:P300 ?borderIso}
SERVICE wikibase:label{bd:serviceParam wikibase:language "en"}
}
GROUP BY ?state ?stateLabel ?iso
ORDER BY ?iso
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?borderIso"):::projected
v3("?borderState"):::projected
v5("?borderStates")
v6("?count")
v1("?iso"):::projected
v2("?state"):::projected
c6(["bd:serviceParam"]):::iri
c8(["en"]):::literal
c2(["wd:Q35657"]):::iri
v2 --"wdt:P31"--> c2
v2 --"wdt:P300"--> v1
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."wdt:P47".-> v3
v3 --"wdt:P31"--> c2
v3 --"wdt:P300"--> v4
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c6 --"wikibase:language"--> c8
end
bind2[/"?borderIso"/]
v4 --o bind2
bind2 --as--o v5
bind3[/"count(?borderState)"/]
v3 --o bind3
bind3 --as--o v6