query-d5294bdab46bb5eca6decf03c3d8741a

rq turtle/ttl

Version 1 - using a named subquery select ?item ?itemLabel ?pit ?value with # here's the start of the named subquery { SELECT ?item (max(?pit) as ?pit) WHERE { values ?item {wd:Q84} ?item p:P1082 ?statement. ?statement pq:P585 ?pit. } group by ?item } as %i # end of named subquery - it finds the max ?pit

where # here is the main query { include %i # it uses the ?item and ?pit values supplied by the named subquery ?item p:P1082 ?statement. ?statement ps:P1082 ?value. # and finds the associated ?value ?statement pq:P585 ?pit. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }

Use at

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#>
# Version 1 - using a named subquery
select ?item ?itemLabel ?pit ?value 
                           # end of named subquery - it finds the max ?pit

where                              # here is the main query
{

{ 
  SELECT ?item (max(?pit) as ?pit)
  WHERE 
  {
    values ?item {wd:Q84}
    ?item p:P1082 ?statement.
    ?statement pq:P585 ?pit.
  } group by ?item 
}                      # it uses the ?item and ?pit values supplied by the named subquery 
  ?item p:P1082 ?statement.
  ?statement ps:P1082 ?value.      # and finds the associated ?value
  ?statement pq:P585 ?pit.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?item"):::projected v4("?pit"):::projected v2("?statement") v4("?value"):::projected c5(["bd:serviceParam"]):::iri c7(["#91;AUTO_LANGUAGE#93;,en"]):::literal bind0[/VALUES ?item/] bind0-->v1 bind00(["wd:Q84"]) bind00 --> bind0 v1 --"p:P1082"--> v2 v2 --"p:qualifier/P585"--> v4 bind2[/"max(?pit)"/] v4 --o bind2 bind2 --as--o v4 v1 --"p:P1082"--> v2 v2 --"p:statement/P1082"--> v4 v2 --"p:qualifier/P585"--> v4 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c5 --"wikibase:language"--> c7 end