query-b97108fb925a770855e80aef5cdce8b1
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
- 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 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
}