query-9627e0aefef7f647b6238d5f7ca8ee06

rq turtle/ttl

Extracting population data from two given yearsHello! I'm stuck here. I would like to extract population data for the last available statement (let's make simple: 2020) and from 10 years ago (2010). I don't know if I could automatically get the "last" and "last-10". I know how to extract the 2020 by hand, but don't know how to get both data. I have tried with ps: and pq: but... I don't know how to specify a year at the pq: level. So I'm here:

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#>
SELECT ?item ?itemLabel ?population ?year WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?item wdt:P31 wd:Q2074737;
    (wdt:P131*) wd:Q93366.
  ?item p:P1082 ?pop.
  ?pop ps:P1082 ?population.
  ?pop pq:P585 ?date.
  BIND(YEAR(?date) as ?year).
  FILTER CONTAINS(?year, "2020").
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?date") v2("?item"):::projected v3("?pop") v4("?population"):::projected v6("?year"):::projected c7(["wd:Q2074737"]):::iri c3(["bd:serviceParam"]):::iri c9(["wd:Q93366"]):::iri c5(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["contains(?year,'2020')"]] f0 --> v6 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c3 --"wikibase:language"--> c5 end v2 --"p:direct/P31"--> c7 v2 --"p:direct/P131"--> c9 v2 --"p:P1082"--> v3 v3 --"p:statement/P1082"--> v4 v3 --"p:qualifier/P585"--> v5 bind1[/"year-from-dateTime(?date)"/] v5 --o bind1 bind1 --as--o v6