query-b194b2a37899351722fe733a7bab16de

rq turtle/ttl

TODO

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
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 ?paysLabel (MAX(year(?p585)) AS ?latest_year) WHERE {
  ?item wdt:P31/wdt:P279* wd:Q1248784; p:P3872 [pq:P585 ?p585] . #all objects that are instance of airport of subclass thereof, with *at least* one P3872 with a P585
  OPTIONAL { 
  ?item p:P3872 [pq:P585 ?year2018 ] . 
   FILTER(("2017-12-31"^^xsd:date < ?year2018) && ("2019-00-00"^^xsd:date > ?year2018))
  }
   FILTER(!(BOUND(?year2018) && !(?year2018=0)))                         # get only airports that don't have a P3872 for 2018 or a P3872 for 2018 with value 0
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,fr". }
  OPTIONAL { ?item wdt:P17 ?pays }
}
GROUP BY ?item ?itemLabel ?paysLabel
ORDER BY ?itemLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?item"):::projected v1("?itemLabel"):::projected v6("?latest_year") v4("?p585"):::projected v5("?pays") v2("?year2018") a1((" ")) a2((" ")) a3((" ")) c12(["#91;AUTO_LANGUAGE#93;,en,fr"]):::literal c6(["wd:Q1248784"]):::iri c10(["bd:serviceParam"]):::iri f0[["not bound(?year2018)not ?year2018 = '0^^xsd:integer'"]] f0 --> v2 v3 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c6 a2 --"p:qualifier/P585"--> v4 v3 --"p:P3872"--> a2 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; a3 -."p:qualifier/P585".-> v2 v3 --"p:P3872"--> a3 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P17".-> v5 end bind2[/"max(year-from-dateTime(?p585))"/] v4 --o bind2 bind2 --as--o v6