query-558ac0db90a4c17f5a8bae740655a667
No ICAO code and might have an IATA code
  SELECT distinct ?item ?itemLabel (group_concat(distinct ?typeLabel; separator = ", ") as ?airport_type) (group_concat(distinct ?countryLabel; separator = ", ") as ?countryL) ?iata ?icao WHERE {
  ?item wdt:P31/wdt:P279 wd:Q1248784.                     # ?item must be an instance of an airport, or an instance that is a subclass of an airport
  ?item wdt:P31 ?type.                                     #get the type
  ?type rdfs:label ?typeLabel. filter(lang(?typeLabel)="en")  #get its label in EN
  optional {?item wdt:P17 ?country .                       # ?item may have a country 
           filter not exists {?country pq:P582 [].}        # ?country that still exists
           ?country rdfs:label ?countryLabel. filter(lang(?countryLabel)="en")}       #get the country label in EN           
  filter not exists {?item wdt:P239 ?icao .}               # there is no ICAO value
  optional {?item p:P238 ?node2.                           # ?item may have a P238 property
            ?node2 ps:P238 ?iata .                         # which has an IATA value
           filter not exists {?node2 pq:P582 [].}   }      # and the value has no P582 end time
  minus {?item wdt:P31/wdt:P279 wd:Q695850.}              # exclude items having instances that are military airports & subclasses thereof
  minus {?item wdt:P31/wdt:P279 wd:Q695850.}              # exclude military airports
  minus {?item wdt:P31/wdt:P279 wd:Q1311670.}             # exclude railways stations
  minus {?item wdt:P31/wdt:P279 wd:Q7373622.}             # exclude Royal Air Force
  minus {?item wdt:P31/wdt:P279 wd:Q502074.}              # exclude héliports
  minus {?item wdt:P576 ?date}                             # exclude destructed airports
  minus {?item wdt:P31/wdt:P279* wd:Q44665966.}            # exclude  airports being build
  minus {?item wdt:P576 [].}                               # remove items with P576 (dissolved, abolished or demolished) as a main property
  minus {?item wdt:P582 [].}                               # remove items with P582 (end date) as a main property
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } . #this bit gets labels for Qid values
} group by ?item ?itemLabel ?iata ?icao order by ?itemLabel
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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#>
# No ICAO code and might have an IATA code
  SELECT distinct ?item ?itemLabel (group_concat(distinct ?typeLabel; separator = ", ") as ?airport_type) (group_concat(distinct ?countryLabel; separator = ", ") as ?countryL) ?iata ?icao WHERE {
  ?item wdt:P31/wdt:P279* wd:Q1248784.                     # ?item must be an instance of an airport, or an instance that is a subclass of an airport
  ?item wdt:P31 ?type.                                     #get the type
  ?type rdfs:label ?typeLabel. filter(lang(?typeLabel)="en")  #get its label in EN
  optional {?item wdt:P17 ?country .                       # ?item may have a country 
           filter not exists {?country pq:P582 [].}        # ?country that still exists
           ?country rdfs:label ?countryLabel. filter(lang(?countryLabel)="en")}       #get the country label in EN             
  filter not exists {?item wdt:P239 ?icao .}               # there is no ICAO value
  optional {?item p:P238 ?node2.                           # ?item may have a P238 property
            ?node2 ps:P238 ?iata .                         # which has an IATA value  
           filter not exists {?node2 pq:P582 [].}   }      # and the value has no P582 end time  
  minus {?item wdt:P31/wdt:P279* wd:Q695850.}              # exclude items having instances that are military airports & subclasses thereof
  minus {?item wdt:P31/wdt:P279* wd:Q695850.}              # exclude military airports
  minus {?item wdt:P31/wdt:P279* wd:Q1311670.}             # exclude railways stations
  minus {?item wdt:P31/wdt:P279* wd:Q7373622.}             # exclude Royal Air Force
  minus {?item wdt:P31/wdt:P279* wd:Q502074.}              # exclude héliports
  minus {?item wdt:P576 ?date}                             # exclude destructed airports
  minus {?item wdt:P31/wdt:P279* wd:Q44665966.}            # exclude  airports being build
  minus {?item wdt:P576 [].}                               # remove items with P576 (dissolved, abolished or demolished) as a main property
  minus {?item wdt:P582 [].}                               # remove items with P582 (end date) as a main property
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } . #this bit gets labels for Qid values
} group by ?item ?itemLabel ?iata ?icao order by ?itemLabel