query-b97108fb925a770855e80aef5cdce8b1

rq turtle/ttl

City and town info

SELECT ?item ?itemLabel ?fips_code ?population ?population_date ?population_methodLabel

WHERE { ?item p:P31/ps:P31/wdt:P279* wd:Q1093829 . # cities ?county wdt:P131 wd:Q1261 . # where the county is in colorado ?item wdt:P131 wd:Q113029 . # and in boulder county

?item wdt:P131 ?county . # county ?county wdt:P131 ?state . # state

OPTIONAL { ?item p:P1082 ?population_statement. ?population_statement ps:P1082 ?population. ?population_statement pq:P585 ?population_date. OPTIONAL {?population_statement pq:P459 ?population_method.} }

FILTER NOT EXISTS { ?item p:P1082/pq:P585 ?population_date_2 . FILTER (?population_date_2 > ?population_date) }

SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } # Helps get the label in your language, if not, then en language }

Use at

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#>
#City and town info

SELECT 
  ?item 
  ?itemLabel
  ?fips_code
  ?population
  ?population_date 
  ?population_methodLabel

WHERE 
{
  ?item p:P31/ps:P31/wdt:P279* wd:Q1093829 . # cities
  ?county wdt:P131 wd:Q1261 . # where the county is in colorado
  ?item wdt:P131 wd:Q113029 . # and in boulder county

  ?item wdt:P131 ?county . #  county
  ?county wdt:P131 ?state . # state

  OPTIONAL {
    ?item p:P1082 ?population_statement.
    ?population_statement ps:P1082 ?population.
    ?population_statement pq:P585 ?population_date.
    OPTIONAL {?population_statement pq:P459 ?population_method.}
  }

  FILTER NOT EXISTS {
    ?item p:P1082/pq:P585 ?population_date_2 .
    FILTER (?population_date_2 > ?population_date)
  }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } # Helps get the label in your language, if not, then en language
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?county") v3("?item"):::projected v7("?population"):::projected v2("?population_date"):::projected v1("?population_date_2") v8("?population_method") v6("?population_statement") v5("?state") a2((" ")) a3((" ")) a1((" ")) c15(["en"]):::literal c6(["wd:Q1093829"]):::iri c13(["bd:serviceParam"]):::iri c9(["wd:Q113029"]):::iri c8(["wd:Q1261"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0f0[["?population_date_2 > ?population_date"]] e0f0 --> e0v1 e0f0 --> e0v2 e0v3 --"p:P1082"--> e0a1 e0a1 --"p:qualifier/P585"--> e0v1 e0v3("?item"):::projected e0v2("?population_date"):::projected e0v1("?population_date_2"):::projected e0a1((" ")):::projected end f0--EXISTS--> f0e0 f0 --> v1 f0 --> v2 f0 --> v3 f0 --> c1 f0 --> a1 f0 --> c2 f1[["?population_date_2 > ?population_date"]] f1 --> v1 f1 --> v2 v3 --"p:P1082"--> a1 a1 --"p:qualifier/P585"--> v1 v3 --"p:P31"--> a2 a2 --"p:statement/P31"--> a3 a3 --"p:direct/P279"--> c6 v4 --"p:direct/P131"--> c8 v3 --"p:direct/P131"--> c9 v3 --"p:direct/P131"--> v4 v4 --"p:direct/P131"--> v5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:P1082".-> v6 v6 --"p:statement/P1082"--> v7 v6 --"p:qualifier/P585"--> v2 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:qualifier/P459".-> v8 end end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c13 --"wikibase:language"--> c15 end