query-867bfa9429c5bae5bd02fed7452ac302
Population ]reply[15:36, 12 September 2018 (UTC)) talk (Vojtěch Dostál have population numbers for different years. Can you set the most up-to-date number as preferred? (Or are you actually doing this already?) Thank you very much --Q2351309Hi, items such as I just stumbled upon the same problem when uploading new population figures with quickstatements: Not only my own updates, but many other entries do not show up in normal queries due to outdated rankings: ]reply[07:01, 29 October 2018 (UTC)) talk (LaboramusIt does but only if there's no other preferred value.
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
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
(MAX(?pref_pop_date) as ?max_date_with_preferred_rank)
(MAX(?norm_pop_date) as ?max_date_with_normal_rank)
WHERE
{
?item p:P31 [ps:P31 wd:Q6256] # Select all countries
OPTIONAL { # Select population dates with preferred rank
?item p:P1082 ?pref_pop.
?pref_pop wikibase:rank wikibase:PreferredRank.
?pref_pop pq:P585 ?pref_pop_date.
}
OPTIONAL { # Select population dates with normal rank
?item p:P1082 ?norm_pop.
?norm_pop wikibase:rank wikibase:NormalRank.
?norm_pop pq:P585 ?norm_pop_date.
}
SERVICE wikibase:label {bd:serviceParam wikibase:language "en".}
}
GROUP BY ?item ?itemLabel
HAVING (
(MAX(?pref_pop_date) < MAX(?norm_pop_date)) # There's data with normal rank available with a point in time later than the one with preferred rank
|| ((COUNT(?norm_pop_date) > 1) && !(BOUND(?max_date_with_preferred_rank)))) # There's more than one point in time, but none is flagged as preferred
ORDER BY ?itemLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?_anon_42b5416610844a34809f33a099ae9de121818")
v9("?_anon_42b5416610844a34809f33a099ae9de121819")
v10("?_anon_42b5416610844a34809f33a099ae9de121820")
v3("?item"):::projected
v1("?itemLabel"):::projected
v11("?max_date_with_normal_rank")
v11("?max_date_with_preferred_rank")
v6("?norm_pop")
v7("?norm_pop_date"):::projected
v4("?pref_pop")
v5("?pref_pop_date"):::projected
a4((" "))
a1((" "))
a2((" "))
a3((" "))
c7(["wikibase:PreferredRank"]):::iri
c9(["wikibase:NormalRank"]):::iri
c13(["en"]):::literal
c11(["bd:serviceParam"]):::iri
c3(["wd:Q6256"]):::iri
f0[["( < || > '1^^xsd:integer'not bound(?max_date_with_preferred_rank))"]]
f0 --> a1
f0 --> a2
f0 --> a3
f0 --> v11
a4 --"p:statement/P31"--> c3
v3 --"p:P31"--> a4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:P1082".-> v4
v4 --"wikibase:rank"--> c7
v4 --"p:qualifier/P585"--> v5
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:P1082".-> v6
v6 --"wikibase:rank"--> c9
v6 --"p:qualifier/P585"--> v7
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c11 --"wikibase:language"--> c13
end
bind6[/"max(?pref_pop_date)"/]
v5 --o bind6
bind6 --as--o v8
bind7[/"max(?norm_pop_date)"/]
v7 --o bind7
bind7 --as--o v9
bind8[/"count(?norm_pop_date)"/]
v7 --o bind8
bind8 --as--o v10
bind9[/"max(?pref_pop_date)"/]
v5 --o bind9
bind9 --as--o v11
bind10[/"max(?norm_pop_date)"/]
v7 --o bind10
bind10 --as--o v11