query-658e675858b6412ecdad80c9ffb9c887

rq turtle/ttl

Find all busstops in Georgia by county SELECT DISTINCT ?busstop ?county WHERE { ?busstop wdt:P31 wd:Q953806 . # is busstop ?busstop wdt:P131+ ?any_county . # located in county ?any_county wdt:P31 wd:Q13410428 . # which is a county of Georgia, USA OPTIONAL { ?busstop wdt:P131*/p:P131/pq:P8000 ?switched_county . # the true county if present ?switched_county wdt:P31 wd:Q13410428 . # if it is a county of Georgia, USA } BIND(COALESCE(?switched_county, ?any_county) AS ?county) }

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
# Find all busstops in Georgia by county
SELECT DISTINCT ?busstop ?county
WHERE
{
  ?busstop wdt:P31 wd:Q953806 .       # is busstop
  ?busstop wdt:P131+ ?any_county .    # located in county
  ?any_county wdt:P31 wd:Q13410428 .  # which is a county of Georgia, USA
  OPTIONAL {
    ?busstop wdt:P131*/p:P131/pq:P8000 ?switched_county . # the true county if present
    ?switched_county wdt:P31 wd:Q13410428 .               # if it is a county of Georgia, USA
  } 
  BIND(COALESCE(?switched_county, ?any_county) AS ?county)
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?any_county") v1("?busstop"):::projected v4("?county"):::projected v3("?switched_county") a1((" ")) a2((" ")) c2(["wd:Q953806"]):::iri c4(["wd:Q13410428"]):::iri v1 --"p:direct/P31"--> c2 v1 --"p:direct/P131"--> v2 v2 --"p:direct/P31"--> c4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P131".-> a1 a1 --"p:P131"--> a2 a2 --"p:qualifier/P8000"--> v3 v3 --"p:direct/P31"--> c4 end bind0[/"?switched_county?any_county"/] v3 --o bind0 v2 --o bind0 bind0 --as--o v4