What is {position held} of {Nursultan Nazarbayev} that is {end time} is {1989-7-27} ?
Ended on July 27th of 1989, when did the Nursultan Nazarbayev hold ended?
What position did Nursultan Nazarbayev hold that ended on July 27th, 1989?
SELECT ?o WHERE { resource:Nursultan_Nazarbayev property:position_held ?c . ?c property:end_time ?y . FILTER ( CONTAINS ( YEAR ( ?y ) , '1989' ) ) . ?c property:position_held ?o }
select distinct ?obj  where {
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <http://wikidata.dbpedia.org/resource/Q57394> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://www.wikidata.org/entity/P39> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> ?obj .
?statement <http://www.wikidata.org/entity/P582> <1989-7-27>
} 

SELECT ?obj WHERE { wd:Q57394 p:P39 ?s . ?s ps:P39 ?obj . ?s pq:P582 ?x filter(contains(YEAR(?x),'1989')) }