query-f7c22482268383cad052c0aa9241ab3c
Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459) Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459) Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459) Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459) Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459) Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459) Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459) Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459) Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459) Propertiesinstance of (P31)population (P1082)point in time (P585)determination method or standard (P459)
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#>
#defaultView:BarChart
# male/female population _must_ not be added unqualified as total population (!)
# this is an error and should be fixed at the item using P1540 and P1539 instead
# (wrong query result may be a manifestation of such)
SELECT ?year (AVG(?pop) AS ?population) ?countryLabel
(COUNT(*) AS ?number_of_chosen_sources) (SAMPLE(?method) AS ?a_source_of_those_chosen)
WHERE
{
?country wdt:P31 wd:Q3624078;#more useful than Q6256;
p:P1082 ?popStatement .
?popStatement ps:P1082 ?pop;
pq:P585 ?date .
BIND(STR(YEAR(?date)) AS ?year)
#FILTER ( (YEAR(?date)) >= 2000 )
# IF multiple ?pop values per country per year exist, we prioritize by source
# census 1st, others 2nd, estimation(s) 3rd, unknown sources (none supplies P459) last
# note: wikibase:rank won't help here: each year may have multiple statements for ?pop value
# rank:prefered is used for the best value (or values) of the latest or current year
# rank:normal may be justified for all of multiple ?pop values for a given year
OPTIONAL { ?popStatement pq:P459 ?method. }
OPTIONAL { ?country p:P1082 [ pq:P585 ?d; pq:P459 ?estimate ].
FILTER(STR(YEAR(?d)) = ?year). FILTER(?estimate = wd:Q791801). }
OPTIONAL { ?country p:P1082 [ pq:P585 ?e; pq:P459 ?census ].
FILTER(STR(YEAR(?e)) = ?year). FILTER(?census = wd:Q39825). }
OPTIONAL { ?country p:P1082 [ pq:P585 ?f; pq:P459 ?other ].
FILTER(STR(YEAR(?f)) = ?year). FILTER(?other != wd:Q39825 && ?other != wd:Q791801). }
BIND(COALESCE(
IF(BOUND(?census), ?census, 1/0),
IF(BOUND(?other), ?other, 1/0),
IF(BOUND(?estimate), ?estimate, 1/0) ) AS ?pref_method).
FILTER(IF(BOUND(?pref_method),?method = ?pref_method,true))
# .. still need to group if multiple values per country per year exist and
# - none is qualified with P459
# - multiple ?estimate or multiple ?census (>1 value from same source)
# - ?other yields more than one source (>1 values are better than optionally
# supplied estimate, but no census source available)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
GROUP BY ?year ?countryLabel
ORDER BY ?year ?countryLabel
Query found at
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/en
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/es
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/fr
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/hy
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/ja
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/nl
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/sv
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/tr
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/uk
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/zh