Reputation: 13920
See eg. P297 at Q37024, there are a qualifier (P582).
This query is wrong, how to show the endtime's like the Q37024 case?
SELECT ?item ?iso2_code ?endtime
WHERE {
?item wdt:P297 ?iso2_code
OPTIONAL { ?iso2_code pq:P582 ?endtime }
}
I need all items that has no endtime.
I am querying
SELECT DISTINCT ?iso2_code ?wd_id
WHERE {
?item wdt:P297 ?iso2_code
BIND(strafter(STR(?item),"http://www.wikidata.org/entity/") as ?wd_id).
} ORDER BY ?iso2_code
but retriving duplicates,
so I need to exclude one, but the correct one: by endtime.
PS: there are a handbook about WIKIDATA Qualifiers but with no real case of retrieving datasets.
Upvotes: 4
Views: 398
Reputation: 11459
SELECT DISTINCT (?simple_value AS ?iso2_code) ?wd_id
WHERE {
?item p:P297 ?statement .
?statement ps:P297 ?simple_value .
# ?statement a wikibase:BestRank
OPTIONAL { ?statement pq:P582 ?qualifier . }
FILTER ( !bound(?qualifier) )
BIND ( strafter(str(?item), str(wd:)) AS ?wd_id ).
} ORDER BY ?iso2_code
You can use FILTER NOT EXISTS { ?statement pq:P582 ?qualifier . }
instead of
OPTIONAL { ?statement pq:P582 ?qualifier . } FILTER ( !bound(?qualifier) )
.
Wikidata data model is documented here. There are many query examples on this page, e. g. this one.
Upvotes: 2