PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?country ( SAMPLE( ?lab ) AS ?countryLabel ) ( SAMPLE( ?popVal ) AS ?population ) ( COUNT( DISTINCT ?airport ) AS ?airportCount ) WHERE {
  ?country wdt:P31 / wdt:P279 * wd:Q6256 .
  OPTIONAL {
    ?country wdt:P1082 ?popVal .
  }
  OPTIONAL {
    ?country rdfs:label ?lab FILTER ( LANG( ?lab ) = "en" )
  }
  {
    {
      ?airport wdt:P31 / wdt:P279 * wd:Q1248784 .
    } UNION {
      ?airport wdt:P31 / wdt:P279 * wd:Q62447 .
    } UNION {
      ?airport wdt:P31 / wdt:P279 * wd:Q3631092 .
    } UNION {
      ?airport wdt:P31 / wdt:P279 * wd:Q695850 .
    }
    {
      ?airport wdt:P17 ?country .
    } UNION {
      ?airport wdt:P131 * ?admin .
      ?admin wdt:P17 ?country .
    }
    FILTER NOT EXISTS {
      ?airport wdt:P582 ?endTime .
    }
    FILTER NOT EXISTS {
      ?airport wdt:P576 ?dissolvedDate .
    }
  }
}
GROUP BY ?country
ORDER BY DESC ( ?airportCount )

Using entities:
- airport (wd:Q1248784), also known as aerodrome, air port, airports: is subclass of Aerodrome / is subclass of aerodrome / is subclass of station / is subclass of organization / is subclass of organisation / location where aircraft take off and land / location where aircraft take off and land / location where aircraft take off and land with extended support facilities, mostly for commercial air transport
- airstrip (wd:Q3631092), also known as airfield, field airstrip, limited services airport, unimproved airport: is subclass of aerodrome / is subclass of Aerodrome / aerodrome with only basic infrastructure and limited or no services not intended for regular commercial use
- aerodrome (wd:Q62447), also known as airdrome, airfield, air navigation feature: is subclass of architectural structure / is subclass of air transport infrastructure / is subclass of station / is subclass of Architectural structure / is subclass of built structure / location from which aircraft flight operations take place
- country (wd:Q6256), also known as countries: is instance of territorial entity type / is instance of administrative territorial entity type / is instance of agent / is subclass of territorial entity / is subclass of territory / is subclass of political territorial entity / distinct territorial body or political entity / distinct territorial body or political entity / region legally identified as a distinct entity in political geography
- air base (wd:Q695850), also known as airbase, air force base, air force station, military air base, military airbase, etc.: is subclass of aerodrome / is subclass of Aerodrome / is subclass of military base / aerodrome used by a military force for the operation of military aircraft

Using properties:
- population (wd:P1082 as wdt), also known as human population, inhabitants, P1082: number of people inhabiting the place; number of people of subject / number of people inhabiting the place; number of people of subject / number of people inhabiting the place; number of people of subject
- located in the administrative territorial entity (wd:P131 as wdt), also known as administrative territorial entity, administrative territory, city, happens in, in, etc.: is subproperty of part of / is subproperty of location / the item is located on the territory of the following administrative entity / the item is located on the territory of the following administrative entity / the item is located on the territory of the following ... the item falls only partially into the administrative entity. / the item is located on the territory of the following ... the item falls only partially into the administrative entity.
- country (wd:P17 as wdt), also known as host country, land, sovereign state, state, P17: is subproperty of located in the administrative territorial entity / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings)
- subclass of (wd:P279 as wdt), also known as all members of this class also belong to, category of, form of, has superclass, is a class of, etc.: this item is a subclass (subset) of that item; ALL instances ... of volcanic landform); Everest is an instance of mountain / this item is a subclass (subset) of that item; all instances ... instance of volcanic landform); K2 is an instance of mountain / this item is a subclass (subset) of that item; all instances ... instance of volcanic landform); K2 is an instance of mountain / this item is a subclass (subset) of that item; all instances ... instance of volcanic landform); K2 is an instance of mountain
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform
- dissolved, abolished or demolished date (wd:P576 as wdt), also known as abolished, abolishment date, ceased date, ceased on, ceased publication, etc.: is subproperty of end time / date or point in time on which the organisation was dissolved/disappeared or the building demolished / point in time at which the subject (organisation, building) ...  "discontinued date" (P2669) for stopping a product
- end time (wd:P582 as wdt), also known as abolished, cease date, cease operation, cease time, closed, etc.: is subproperty of point in time / indicates the time an item ceases to exist or a statement stops being valid / indicates the time an item ceases to exist or a statement stops being valid / moment when an entity ceases to exist and a statement stops being entirely valid or no longer be true

Got 212 rows and 4 columns, showing the first 5 and last 5 rows below:
| country                  | countryLabel            | population              | airportCount    |
| ------------------------ | ----------------------- | ----------------------- | --------------- |
| United States (wd:Q30)   | United States (lang:en) | 340110988 (xsd:decimal) | 23954 (xsd:int) |
| Australia (wd:Q408)      | Australia (lang:en)     | 26473055 (xsd:decimal)  | 2995 (xsd:int)  |
| Brazil (wd:Q155)         | Brazil (lang:en)        | 203062512 (xsd:decimal) | 2973 (xsd:int)  |
| Canada (wd:Q16)          | Canada (lang:en)        | 36991981 (xsd:decimal)  | 1765 (xsd:int)  |
| Colombia (wd:Q739)       | Colombia (lang:en)      | 52321152 (xsd:decimal)  | 910 (xsd:int)   |
| ...                      | ...                     | ...                     | ...             |
| Palestine (wd:Q219060)   | Palestine (lang:en)     | 5227193 (xsd:decimal)   | 1 (xsd:int)     |
| Andorra (wd:Q228)        | Andorra (lang:en)       | 87097 (xsd:decimal)     | 1 (xsd:int)     |
| Sint Maarten (wd:Q26273) | Sint Maarten (lang:en)  | 43847 (xsd:decimal)     | 1 (xsd:int)     |
| Monaco (wd:Q235)         | Monaco (lang:en)        | 38350 (xsd:decimal)     | 1 (xsd:int)     |
| Vatican City (wd:Q237)   | Vatican City (lang:en)  | 764 (xsd:decimal)       | 1 (xsd:int)     |

Answer:
I executed the query that: for each country (wd:Q6256), counts distinct airports that are instances (or instances of subclasses) of airport/aerodrome/airstrip/air base, excludes airports having an end time (P582) or a dissolved/abolished/demolished date (P576), and retrieves the (direct) population value (wdt:P1082) where available. The query returns one row per country with: country IRI, English label, population (wdt:P1082 if present), and airportCount (number of operational airports as defined).

Summary of the result set: 212 countries were returned. Example rows (country label — population — airportCount):
- United States — 340110988 — 23954
- Australia — 26473055 — 2995
- Brazil — 203062512 — 2973
- Canada — 36991981 — 1765
- Colombia — 52321152 — 910

Notes, assumptions and caveats:
- Airport classes included: airport (wd:Q1248784), aerodrome (wd:Q62447), airstrip (wd:Q3631092), and air base (wd:Q695850). If you prefer a different/expanded set of classes (e.g., include military-only facilities or additional subclass types), I can adjust the query.
- Country assignment uses either wdt:P17 on the airport item or an admin-parent (wdt:P131*) whose wdt:P17 gives the country. This helps include airports whose direct P17 is missing but an admin parent has the country.
- The query excludes any airport that has a direct wdt:P582 (end time) value or wdt:P576 (dissolved/abolished/demolished date) value. Some closed facilities might instead be modeled differently on Wikidata (e.g., with statements about status) and could still appear; if you want to also exclude items with certain status properties, I can expand the filters.
- Population values are taken from wdt:P1082 (direct population value). I did not disambiguate different population statements or pick a latest point-in-time qualifier; if you need the most recent population statement with its date (pq:P585), I can rewrite the query to return the population value and its point-in-time qualifier (selecting the latest) for each country.

If you want, I can:
- Return the full table as CSV/TSV, or
- Modify the class list for airports, or
- Use the population time-series to pick the most recent population with its date.

If you want the full results now (all 212 rows) in table or CSV form, tell me which format you prefer and I will provide them.

I executed the query that: for each country (wd:Q6256), counts distinct airports that are instances (or instances of subclasses) of airport/aerodrome/airstrip/air base, excludes airports having an end time (P582) or a dissolved/abolished/demolished date (P576), and retrieves the (direct) population value (wdt:P1082) where available. The query returns one row per country with: country IRI, English label, population (wdt:P1082 if present), and airportCount (number of operational airports as defined).

Summary of the result set: 212 countries were returned. Example rows (country label — population — airportCount):
- United States — 340110988 — 23954
- Australia — 26473055 — 2995
- Brazil — 203062512 — 2973
- Canada — 36991981 — 1765
- Colombia — 52321152 — 910

Notes, assumptions and caveats:
- Airport classes included: airport (wd:Q1248784), aerodrome (wd:Q62447), airstrip (wd:Q3631092), and air base (wd:Q695850). If you prefer a different/expanded set of classes (e.g., include military-only facilities or additional subclass types), I can adjust the query.
- Country assignment uses either wdt:P17 on the airport item or an admin-parent (wdt:P131*) whose wdt:P17 gives the country. This helps include airports whose direct P17 is missing but an admin parent has the country.
- The query excludes any airport that has a direct wdt:P582 (end time) value or wdt:P576 (dissolved/abolished/demolished date) value. Some closed facilities might instead be modeled differently on Wikidata (e.g., with statements about status) and could still appear; if you want to also exclude items with certain status properties, I can expand the filters.
- Population values are taken from wdt:P1082 (direct population value). I did not disambiguate different population statements or pick a latest point-in-time qualifier; if you need the most recent population statement with its date (pq:P585), I can rewrite the query to return the population value and its point-in-time qualifier (selecting the latest) for each country.

If you want, I can:
- Return the full table as CSV/TSV, or
- Modify the class list for airports, or
- Use the population time-series to pick the most recent population with its date.

If you want the full results now (all 212 rows) in table or CSV form, tell me which format you prefer and I will provide them.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?country ( SAMPLE( ?lab ) AS ?countryLabel ) ( SAMPLE( ?popVal ) AS ?population ) ( COUNT( DISTINCT ?airport ) AS ?airportCount ) WHERE {
  ?country wdt:P31 / wdt:P279 * wd:Q6256 .
  OPTIONAL {
    ?country wdt:P1082 ?popVal .
  }
  OPTIONAL {
    ?country rdfs:label ?lab FILTER ( LANG( ?lab ) = "en" )
  }
  {
    {
      ?airport wdt:P31 / wdt:P279 * wd:Q1248784 .
    } UNION {
      ?airport wdt:P31 / wdt:P279 * wd:Q62447 .
    } UNION {
      ?airport wdt:P31 / wdt:P279 * wd:Q3631092 .
    } UNION {
      ?airport wdt:P31 / wdt:P279 * wd:Q695850 .
    }
    {
      ?airport wdt:P17 ?country .
    } UNION {
      ?airport wdt:P131 * ?admin .
      ?admin wdt:P17 ?country .
    }
    FILTER NOT EXISTS {
      ?airport wdt:P582 ?endTime .
    }
    FILTER NOT EXISTS {
      ?airport wdt:P576 ?dissolvedDate .
    }
  }
}
GROUP BY ?country
ORDER BY DESC ( ?airportCount )

Using entities:
- airport (wd:Q1248784), also known as aerodrome, air port, airports: is subclass of Aerodrome / is subclass of aerodrome / is subclass of station / is subclass of organization / is subclass of organisation / location where aircraft take off and land / location where aircraft take off and land / location where aircraft take off and land with extended support facilities, mostly for commercial air transport
- airstrip (wd:Q3631092), also known as airfield, field airstrip, limited services airport, unimproved airport: is subclass of aerodrome / is subclass of Aerodrome / aerodrome with only basic infrastructure and limited or no services not intended for regular commercial use
- aerodrome (wd:Q62447), also known as airdrome, airfield, air navigation feature: is subclass of architectural structure / is subclass of air transport infrastructure / is subclass of station / is subclass of Architectural structure / is subclass of built structure / location from which aircraft flight operations take place
- country (wd:Q6256), also known as countries: is instance of territorial entity type / is instance of administrative territorial entity type / is instance of agent / is subclass of territorial entity / is subclass of territory / is subclass of political territorial entity / distinct territorial body or political entity / distinct territorial body or political entity / region legally identified as a distinct entity in political geography
- air base (wd:Q695850), also known as airbase, air force base, air force station, military air base, military airbase, etc.: is subclass of aerodrome / is subclass of Aerodrome / is subclass of military base / aerodrome used by a military force for the operation of military aircraft

Using properties:
- population (wd:P1082 as wdt), also known as human population, inhabitants, P1082: number of people inhabiting the place; number of people of subject / number of people inhabiting the place; number of people of subject / number of people inhabiting the place; number of people of subject
- located in the administrative territorial entity (wd:P131 as wdt), also known as administrative territorial entity, administrative territory, city, happens in, in, etc.: is subproperty of part of / is subproperty of location / the item is located on the territory of the following administrative entity / the item is located on the territory of the following administrative entity / the item is located on the territory of the following ... the item falls only partially into the administrative entity. / the item is located on the territory of the following ... the item falls only partially into the administrative entity.
- country (wd:P17 as wdt), also known as host country, land, sovereign state, state, P17: is subproperty of located in the administrative territorial entity / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings)
- subclass of (wd:P279 as wdt), also known as all members of this class also belong to, category of, form of, has superclass, is a class of, etc.: this item is a subclass (subset) of that item; ALL instances ... of volcanic landform); Everest is an instance of mountain / this item is a subclass (subset) of that item; all instances ... instance of volcanic landform); K2 is an instance of mountain / this item is a subclass (subset) of that item; all instances ... instance of volcanic landform); K2 is an instance of mountain / this item is a subclass (subset) of that item; all instances ... instance of volcanic landform); K2 is an instance of mountain
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform
- dissolved, abolished or demolished date (wd:P576 as wdt), also known as abolished, abolishment date, ceased date, ceased on, ceased publication, etc.: is subproperty of end time / date or point in time on which the organisation was dissolved/disappeared or the building demolished / point in time at which the subject (organisation, building) ...  "discontinued date" (P2669) for stopping a product
- end time (wd:P582 as wdt), also known as abolished, cease date, cease operation, cease time, closed, etc.: is subproperty of point in time / indicates the time an item ceases to exist or a statement stops being valid / indicates the time an item ceases to exist or a statement stops being valid / moment when an entity ceases to exist and a statement stops being entirely valid or no longer be true

Execution result:
Got 212 rows and 4 columns, showing the first 5 and last 5 rows below:
| country                  | countryLabel            | population              | airportCount    |
| ------------------------ | ----------------------- | ----------------------- | --------------- |
| United States (wd:Q30)   | United States (lang:en) | 340110988 (xsd:decimal) | 23954 (xsd:int) |
| Australia (wd:Q408)      | Australia (lang:en)     | 26473055 (xsd:decimal)  | 2995 (xsd:int)  |
| Brazil (wd:Q155)         | Brazil (lang:en)        | 203062512 (xsd:decimal) | 2973 (xsd:int)  |
| Canada (wd:Q16)          | Canada (lang:en)        | 36991981 (xsd:decimal)  | 1765 (xsd:int)  |
| Colombia (wd:Q739)       | Colombia (lang:en)      | 52321152 (xsd:decimal)  | 910 (xsd:int)   |
| ...                      | ...                     | ...                     | ...             |
| Palestine (wd:Q219060)   | Palestine (lang:en)     | 5227193 (xsd:decimal)   | 1 (xsd:int)     |
| Andorra (wd:Q228)        | Andorra (lang:en)       | 87097 (xsd:decimal)     | 1 (xsd:int)     |
| Sint Maarten (wd:Q26273) | Sint Maarten (lang:en)  | 43847 (xsd:decimal)     | 1 (xsd:int)     |
| Monaco (wd:Q235)         | Monaco (lang:en)        | 38350 (xsd:decimal)     | 1 (xsd:int)     |
| Vatican City (wd:Q237)   | Vatican City (lang:en)  | 764 (xsd:decimal)       | 1 (xsd:int)     |

[System]
You are a question answering assistant. Your job is to generate a SPARQL query to answer a given user question.

You should follow a step-by-step approach to generate the SPARQL query:
1. Determine possible entities and properties implied by the user question.
2. Search for the entities and properties in the knowledge graphs. Where applicable, constrain the searches with already identified entities and properties.
3. Gradually build up the SPARQL query using the identified entities and properties. Start with simple queries and add more complexity as needed. Execute intermediate queries to get feedback and to verify your assumptions. You may need to refine or rethink your current plan based on the query results and go back to step 2 if needed, possibly multiple times.
4. Use the answer or cancel function to finalize your answer and stop the generation process.

Available knowledge graphs:
- wikidata at http://localhost:7001 with prefix index for entities and similarity index for properties, and notes:
  - P106 = occupation. Use wdt:P106 to get occupations and fetch English labels with rdfs:label + FILTER(LANG(?label)="en"). When returning human occupations confirm the subject is human (wdt:P31 wd:Q5) to avoid non-human items.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for quick/direct values; for time-series/point-in-time use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect statement qualifiers (e.g., 'applies to part') and prov:wasDerivedFrom references (pr:P854 etc.) to detect city-proper vs metro/prefecture scopes before using values.
  - Common person properties: P31 (instance of human Q5), P106 (occupation), P569 (date of birth), P19 (place of birth), P27 (country of citizenship), P21 (sex/gender), P166 (award received). Use wdt: for direct values when possible.
  - P17 (country) can be incomplete/misleading for places (historical/overseas tags). To get modern cities in a country combine: instance-of city (P31=Q515) + wdt:P17 OR use wdt:P131* to find an admin parent whose wdt:P17 = the country. Also cross-check coordinates (P625) or admin hierarchy to spot outliers.
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Be aware many items have year-only or imprecise dates and coverage is biased toward notable/public figures (sportspeople, politicians, artists).
  - To retrieve qualifiers (e.g., award year) use the statement/qualifier pattern: p:Pxxx / ps:Pxxx / pq:P585. Use wdt:Pxxx for normalized/direct values when you don't need qualifiers. Example: p:P166 + pq:P585 gives award year.
  - To get a person's occupations: use wdt:P106 for direct/normalized values and rdfs:label for human-readable names (FILTER(LANG(...))). Example: wd:Q... wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel)="en").
  - P166 = award received. Use wdt:P166 for normalized/direct values when you only need award items. To get award years or qualifiers use p:P166 / ps:P166 / pq:P585. Many statements lack pq:P585 — use OPTIONAL { ?stmt pq:P585 ?date } and ORDER BY DESC(?date). When listing award winners, filter ?person wdt:P31 wd:Q5 to ensure humans.
  - Population time-series pattern: wd:Q... p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . ORDER BY DESC(?date). pq:P585 is the point-in-time qualifier. IMPORTANT: time-series may mix scopes (city proper vs metro) — e.g., Tokyo has a 2016 entry ~38,140,000 likely metro vs smaller city figures. Inspect qualifiers/references for scope before use.
  - Use wdt:P131* to traverse the admin hierarchy and compare wdt:P17 on the place vs an admin parent to detect historical/colonial country assignments. When mismatches appear, inspect the admin parent's instance-of (P31), labels, qualifiers and references to interpret the historical scope.
  - wdt:P106 often yields multiple occupations for a person. Use GROUP_CONCAT(DISTINCT ?occLabel; separator=", ") or return multiple rows. Always fetch labels with rdfs:label + FILTER(LANG(?label)="en") to get readable occupation names.
  - When a search_entity returns multiple hits (person vs sculpture vs memorial), confirm you selected the human/statements by checking wdt:P31 (instance of) and relevant wdt: properties (e.g., wdt:P106). This avoids using a non-human QID by mistake.
  - search_autocomplete can be constrained with a SPARQL pattern containing ?search (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }). Use constraints to focus results (e.g., humans) and avoid ambiguous fallbacks; if it returns no results, fallback to search_entity and verify wdt:P31.
  - Use search_property_of_entity to find relevant properties for an entity (e.g., 'award' -> P166) and search_object_of_property to discover candidate objects (e.g., 'physicist' for P106). This reduces guessing P/Q ids and surfaces qualifiers.
  - Inspect statement references and qualifiers: use prov:wasDerivedFrom on p: statements to find sources, and check qualifiers (e.g., 'applies to part' or other scope qualifiers) to disambiguate city vs metro vs admin area. Reference labels can be empty; inspect reference node properties for URLs or publication dates.

Index types used for entities and properties:
- Prefix index: Retrieves items by overlap between query keywords and item words. The query keywords can match item words exactly or as prefixes.
- Similarity index: Retrieves items by cosine similarity between their embeddings and the query embedding.

General notes across knowledge graphs:
- Use rdfs:label + FILTER(LANG(?label)="en") for labels; avoid SERVICE wikibase:label. Use wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access statement qualifiers (e.g., award year via pq:P585). When dates matter, prefer xsd:dateTime and watch for year-only precision.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct/normalized values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (dates via pq:P585). For dates use xsd:dateTime and expect year-only precision. For places: combine P17 with P131 or coordinate (P625) filters to avoid historical/overseas mismatches.
- Use OPTIONAL for pq: qualifiers (e.g., pq:P585), sort by qualifier (ORDER BY pq:P585 DESC) to prefer recent values. Use GROUP_CONCAT to combine multiple labels/values in one row. Watch for typed literals (xsd:dateTime, xsd:decimal) when filtering or sorting.
- Before querying, use search_entity to resolve human-friendly names to wd:Q identifiers and verify instance-of (e.g., check wdt:P31 = wd:Q5 for humans) to avoid ambiguous matches. Prefer the top match but programmatically confirm P31 before using its data.
- Use search_property to confirm property identifiers (e.g., "country" -> P17) before embedding them in queries. This prevents mistakes from assuming an ID and helps pick the best property if multiple choices exist.
- search_autocomplete can fall back to an unconstrained search or error when there are too many candidates. If this happens (e.g., "more than the maximum supported number of subject candidates"), retry with narrower constraints such as instance-of (wdt:P31), additional type filters, or short prefixes to reduce the candidate set; otherwise fallback to search_entity and verify wdt:P31.
- Use list(...) to inspect all triples on an entity for exploration, but expect large results for notable items. Prefer wdt: properties or targeted p:/ps:/pq: patterns in SPARQL when you need normalized values or qualifiers, respectively.
- Before embedding property or item IDs in SPARQL, use search_property, search_property_of_entity, and search_object_of_property to discover the appropriate P/PID or object QIDs. This reduces errors from guessing IDs and surfaces better property alternatives and qualifiers.
- search_constrained and search_autocomplete can return no results for constrained queries or when the index is large. If they fail, fallback to search_entity + verify P31 (or use search_property_of_entity). Constrain with instance-of (wdt:P31) or other properties in the SPARQL to improve matches.
- When selecting awards by year, prefer xsd:dateTime range filters (e.g., >= "2001-01-01T00:00:00Z"^^xsd:dateTime && < "2002-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for portability and precision.
- When selecting award winners via wdt:P166, filter ?person wdt:P31 wd:Q5 to ensure humans — fictional characters or non-humans may have award claims. If you need award years use p:P166 / ps:P166 / pq:P585 and OPTIONAL { ?stmt pq:P585 ?year } to retrieve qualifier years.
- Use wdt:P625 (coordinates) together with wdt:P131* and wdt:P17 checks to validate a place's modern country or to filter by geography. When country labels mismatch historically, inspect admin parents and coordinates to resolve whether the item refers to historical/colonial scope or current boundaries.
- Prefer wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (e.g., pq:P585 for award year). Always fetch labels with rdfs:label + FILTER(LANG(?label) = "en").
- If search_autocomplete returns too many candidates or errors, retry with constraints (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }) or narrower query text. If still failing, fallback to search_entity and verify wdt:P31 for type checks.
- For award-year queries use p:P166 / ps:P166 / pq:P585 to access award statements and year qualifiers. Filter by xsd:dateTime ranges (e.g., >= "2020-01-01T00:00:00Z"^^xsd:dateTime && < "2021-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for robustness.
- Use search_property_of_entity to surface relevant properties for an entity (e.g., 'birth' -> P569/P19). list(...) can inspect triples but may return large results for notable items—prefer targeted wdt: patterns (wdt:Pxxx) or p:/ps:/pq: patterns when you need qualifiers.

SPARQL prefixes for use in function calls:
- bd: <http://www.bigdata.com/rdf#
- cc: <http://creativecommons.org/ns#
- data: <https://www.wikidata.org/wiki/Special:EntityData/
- dc: <http://purl.org/dc/elements/1.1/
- dct: <http://purl.org/dc/terms/
- foaf: <http://xmlns.com/foaf/0.1/
- geo: <http://www.opengis.net/ont/geosparql#
- geof: <http://www.opengis.net/def/function/geosparql/
- gn: <http://www.geonames.org/ontology#
- hint: <http://www.bigdata.com/queryHints#
- imdb: <https://www.imdb.com/
- math: <http://www.w3.org/2005/xpath-functions/math#
- ontolex: <http://www.w3.org/ns/lemon/ontolex#
- owl: <http://www.w3.org/2002/07/owl#
- p: <http://www.wikidata.org/prop/
- pq: <http://www.wikidata.org/prop/qualifier/
- pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/
- pqv: <http://www.wikidata.org/prop/qualifier/value/
- pr: <http://www.wikidata.org/prop/reference/
- prn: <http://www.wikidata.org/prop/reference/value-normalized/
- prov: <http://www.w3.org/ns/prov#
- prv: <http://www.wikidata.org/prop/reference/value/
- ps: <http://www.wikidata.org/prop/statement/
- psn: <http://www.wikidata.org/prop/statement/value-normalized/
- psv: <http://www.wikidata.org/prop/statement/value/
- qb: <http://purl.org/linked-data/cube#
- qfn: <http://qlever.cs.uni-freiburg.de/function#
- ql: <http://qlever.cs.uni-freiburg.de/builtin-functions/
- qlss: <https://qlever.cs.uni-freiburg.de/spatialSearch/
- rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#
- rdfs: <http://www.w3.org/2000/01/rdf-schema#
- ref: <http://www.wikidata.org/reference/
- s: <http://www.wikidata.org/entity/statement/
- schema: <http://schema.org/
- skos: <http://www.w3.org/2004/02/skos/core#
- v: <http://www.wikidata.org/value/
- void: <http://rdfs.org/ns/void#
- wd: <http://www.wikidata.org/entity/
- wdno: <http://www.wikidata.org/prop/novalue/
- wdt: <http://www.wikidata.org/prop/direct/
- wdtn: <http://www.wikidata.org/prop/direct-normalized/
- wikibase: <http://wikiba.se/ontology#
- xsd: <http://www.w3.org/2001/XMLSchema#

Additional rules to follow:
- Explain your thought process before and after each step and function call.
- Do not just use or make up entity or property identifiers without verifying their existence in the knowledge graphs first.
- Do not ask the user for clarifications without first attempting to complete the task. If the task input is incomplete or ambiguous, try to make reasonable assumptions and document them.
- Do not use "SERVICE wikibase:label { bd:serviceParam wikibase:language ..." in SPARQL queries. It is not SPARQL standard and unsupported by the used QLever SPARQL endpoints. Use rdfs:label or similar properties to get labels instead.
- Always execute your final SPARQL query before giving an answer to make sure it returns the expected results.
- The SPARQL query should always return the actual identifiers / IRIs of the items in its result. It additionally may return labels or other human-readable information, but they are optional and should be put within optional clauses unless explicitly requested by the user.
- Do not stop early if there are still obvious improvements to be made to the SPARQL query. For example, keep refining your SPARQL query if its result contains irrelevant items or is missing items you expected.
- Do not perform additional computation (e.g. filtering, sorting, calculations) on the result of the SPARQL query to determine the answer. All computation should be done solely within SPARQL.
- For questions with a "True" or "False" answer the SPARQL query should be an ASK query.

[User] What is the current number of operational airports and the population for each country, excluding airports that have an end time or a dissolved, abolished, or demolished date, if available?

[Assistant]
Step 1 — I'll search Wikidata for the item representing "airport" so I can use its Q-id in the query. I will also look up properties for "end time" and "dissolved, abolished or demolished date" to verify their P-ids. I'll run a few searches and explain results. I'll start by searching for "airport".

Question: airport

Top 10 entity alternatives:
1. airport (wd:Q1248784), also known as aerodrome, air port, airports: location where aircraft take off and land with extended support facilities, mostly for commercial air transport / location where aircraft take off and land / location where aircraft take off and land / is subclass of organisation / is subclass of organization / is subclass of aerodrome / is subclass of Aerodrome / is subclass of station
2. Airport (wd:Q409022): 1970 film directed by George Seaton / is instance of film
3. AirPort (wd:Q697292), also known as Apple AirPort: brand of wifi router equipment made by Apple Inc. / is instance of brand / Apple AirPort
4. Airport (wd:Q4698872), also known as Airport, CA, Airport, California: census-designated place in Stanislaus County, California, USA / is instance of census-designated place in the United States / is instance of census-designated place
5. Airport (wd:Q2604087): is instance of literary work / 1968 novel by Arthur Hailey
6. Kasese Airport (wd:Q6374123, matched via Airport), also known as Airport, HUKS, KSE: is instance of commercial traffic aerodrome / is instance of airport / airport in Uganda
7. Basongo Airport (wd:Q3339360, matched via airport), also known as airport, BAN, FZVR: airport in Democratic Republic of the Congo / is instance of airport
8. Airport (wd:Q11289474), also known as Rapid Airport: is instance of passenger train service / is instance of airport rail link / Rapid trains in Hokkaido, Japan / is instance of train service / is instance of rapid train
9. Bambili-Dingila Airport (wd:Q3206837, matched via airport), also known as Aéroport de Bambili-Dingila, airport, FZKB: airport in Democratic Republic of the Congo / is instance of aerodrome / is instance of Aerodrome
10. Airport (wd:Q4073688), also known as Airport Station: station on the RTA Red Line in Cleveland, Ohio, United States / is instance of airport railway station / is instance of underground station / is instance of metro station

[Assistant]
I'll search for the property corresponding to "end time" and to "dissolved, abolished or demolished date" to confirm their P-numbers.

Question: end time

Top 10 property alternatives:
1. end time (wd:P582 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as abolished, cease date, cease operation, cease time, closed, etc.: moment when an entity ceases to exist and a statement stops being entirely valid or no longer be true / indicates the time an item ceases to exist or a statement stops being valid / indicates the time an item ceases to exist or a statement stops being valid / is subproperty of point in time
2. start time (wd:P580 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as began, beginning, building date, effective, effectivity, etc.: indicates the time an item begins to exist or a statement starts being valid / indicates the time an item begins to exist or a statement starts being valid / time an entity begins to exist or a statement starts being valid / is subproperty of point in time
3. work period (end) (wd:P2032 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via end time for work), also known as active until, date of activity (end), end date of activity, end time for work, fl. (end), etc.: end of period during which a person or group flourished (fl. = "floruit") in their professional activity / end of period during which a person or group flourished (fl. = "floruit") in their professional activity / is subproperty of end time / is subproperty of floruit
4. duration (wd:P2047 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via time interval), also known as cook time, era, interval, length, length of time, etc.: length of time of an event or process / length of time of an event or process / length of time of an event or process
5. time played (wd:P9140 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as minutes played, P9140: time (usually minutes) played by a participant in a sporting event
6. dissolved, abolished or demolished date (wd:P576 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via time abolished), also known as abolished, abolishment date, ceased date, ceased on, ceased publication, etc.: point in time at which the subject (organisation, building) ...  "discontinued date" (P2669) for stopping a product / date or point in time on which the organisation was dissolved/disappeared or the building demolished / is subproperty of end time
7. end period (wd:P3416 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as until period, P3416: last period in which the statement is still valid (including the period-value)
8. point in time (wd:P585 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via at time), also known as as of, at time, by date, date, during, etc.: date something took place, existed or a statement was true; for providing time use the "refine date" property (P4241) / time and date something took place, existed or a statement was true / time and date something took place, existed or a statement was true / time and date something took place, existed or a statement was true
9. refine date (wd:P4241 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via specific time), also known as date refinement, exact time, hour, local time, quarter, etc.: qualifier to narrow down the precision of a date not fully specified by the Wikidata time datatype precision field / qualifier to narrow down the precision of a date not fully specified by the Wikidata time datatype precision field
10. time gap (wd:P2911 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as gap, P2911: time gap to winner time (P2781)

[Assistant]
I'll search for related classes of "airport" (subclasses/related items) to ensure I count common airport-like instances too (e.g., aerodrome, airfield). I will search for "aerodrome" and "airfield" to see their Q-ids.

Question: aerodrome

Top 10 entity alternatives:
1. airport (wd:Q1248784, matched via aerodrome), also known as aerodrome, air port, airports: location where aircraft take off and land with extended support facilities, mostly for commercial air transport / location where aircraft take off and land / location where aircraft take off and land / is subclass of organization / is subclass of organisation / is subclass of Aerodrome / is subclass of aerodrome / is subclass of station
2. aerodrome (wd:Q62447), also known as airdrome, airfield, air navigation feature: location from which aircraft flight operations take place / is subclass of air transport infrastructure / is subclass of architectural structure / is subclass of Architectural structure / is subclass of built structure / is subclass of station
3. Aerodrome (wd:Q381424), also known as Aerodrome (Austria), Aerodrome (music festival): music festival in Wiener Neustadt, Austria / is instance of music festival
4. Aerodrome (wd:Q108080429): is instance of protected area / protected area in France
5. Aerodrome (wd:Q116446160): map in the 2018 video game Battlefield V / is instance of level
6. Perth Airport (wd:Q45935, matched via Guildford Aerodrome), also known as Guildford Aerodrome, PER, PERTH, Perth Domestic Airport, Perth International Airport: international airport in Perth, Western Australia / is instance of commercial traffic aerodrome / is instance of international airport
7. Oulu Airport (wd:Q1131604, matched via Oulu Aerodrome), also known as EFOU, OUL, Oulu Aerodrome, Oulu Airfield, OULU airport, etc.: is instance of commercial traffic aerodrome / is instance of international airport / airport in Oulu, Finland / is instance of airport
8. Naha Airport (wd:Q1197455, matched via Oroku Aerodrome), also known as OKA, Oroku Aerodrome, ROAH, 那　覇, 那覇: is instance of commercial traffic aerodrome / airport serving Okinawa, Japan / is instance of airport
9. Kemi-Tornio Airport (wd:Q1413172, matched via Kemi-Tornio Aerodrome), also known as EFKE, KEM, Kemi Airport, Kemi-Tornio Aerodrome, KEMI-TORNIO airport, etc.: is instance of commercial traffic aerodrome / airport in Kemi, Finland / is instance of airport
10. Kajaani Airport (wd:Q739238, matched via Kajaani Aerodrome), also known as EFKI, KAJ, Kajaani Aerodrome, KAJAANI airport, Paltaniemi Airport: is instance of commercial traffic aerodrome / airport in Kajaani, Finland / is instance of airport

[Assistant]
I'll also search for "airfield" to capture other common class names and then plan the airport type matching (instance-of airport OR instance-of aerodrome OR instance-of airfield / subclasses). Then I'll build a SPARQL query that:
- selects items that are instances of airport/aerodrome/airfield (or their subclasses)
- assigns them to a country via wdt:P17 or via wdt:P131* traversal to an admin parent whose wdt:P17 is the country
- excludes those with wdt:P582 (end time) or wdt:P576 (dissolved, abolished or demolished date)
- counts airports per country
- retrieves population wdt:P1082 for each country (optional fallback if missing)
I'll now search for "airfield".

Question: airfield

Top 10 entity alternatives:
1. aerodrome (wd:Q62447, matched via airfield), also known as airdrome, airfield, air navigation feature: location from which aircraft flight operations take place / is subclass of air transport infrastructure / is subclass of architectural structure / is subclass of Architectural structure / is subclass of built structure / is subclass of station
2. airstrip (wd:Q3631092, matched via airfield), also known as airfield, field airstrip, limited services airport, unimproved airport: aerodrome with only basic infrastructure and limited or no services not intended for regular commercial use / is subclass of aerodrome / is subclass of Aerodrome
3. Airfield (wd:Q123367481): is instance of wards and electoral divisions of the United Kingdom / electoral ward in the London Borough of Havering from 1978 to 2002 / is instance of ward or electoral division of the United Kingdom
4. Airfield (wd:Q119386964): painting by Malcolm Ryan (b.1938), Colchester and Ipswich Museums Service: Ipswich Borough Council Collection / is instance of painting
5. air base (wd:Q695850, matched via military airfield), also known as airbase, air force base, air force station, military air base, military airbase, etc.: aerodrome used by a military force for the operation of military aircraft / is subclass of military base / is subclass of aerodrome / is subclass of Aerodrome
6. Tunis–Carthage International Airport (wd:Q1141214, matched via Tunis Airfield), also known as Aeroport international de Tunis-Carthage, Aéroport international de Tunis-Carthage, Carthage Airport, DTTA, TUN, etc.: international airport serving Tunis, the capital city of Tunisia / is instance of commercial traffic aerodrome / is instance of airport / airport in Tunisia / airport in Tunisia
7. Xiamen Gaoqi International Airport (wd:Q177216, matched via Amoy Airfield), also known as Amoy Airfield, Gaoqi Guoji Jichang, XMN, ZSAM: International airport in Xiamen City, Foojian Privince, Chian / is instance of commercial traffic aerodrome / airport in People's Republic of China / airport in People's Republic of China / is instance of international airport / is instance of airport
8. Oulu Airport (wd:Q1131604, matched via Oulu Airfield), also known as EFOU, OUL, Oulu Aerodrome, Oulu Airfield, OULU airport, etc.: is instance of commercial traffic aerodrome / is instance of international airport / airport in Oulu, Finland / is instance of airport
9. Kandahar International Airport (wd:Q33156, matched via Kandahar Airfield), also known as KAF, Kandahar Airfield, Kandahar Airport, KDH, OAKN: international airport serving Kandahar, Afghanistan / international airport serving Kandahar, Afghanistan / is instance of commercial traffic aerodrome / is instance of international airport
10. Jacksons International Airport (wd:Q1088438, matched via Jackson Airfield), also known as 7 Mile Drome, AYPY, Jackson Airfield, Jacksons Airport, POM, etc.: international airport in Port Moresby, Papua New Guinea / is instance of commercial traffic aerodrome / is instance of international airport / is instance of airport

[Assistant]
Explanation of the planned final query:
- I will count distinct airports per country where the airport is an instance (or instance of a subclass) of airport/aerodrome/airstrip/air base.
- I will exclude airports that have an end time (P582) or dissolved/abolished/demolished date (P576).
- I will assign country either via wdt:P17 or via the admin parent chain wdt:P131* whose wdt:P17 gives the country.
- I will retrieve each country's population using wdt:P1082 when available.
- I will group by country and return the country IRI, its English label, the population value (sampled), and the count of operational airports.

Now I'll execute the SPARQL query to get the results.

execute

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?country (SAMPLE(?countryLabel) AS ?countryLabel) (SAMPLE(?population) AS ?population) (COUNT(DISTINCT ?airport) AS ?airportCount)
WHERE {
  # restrict to countries
  ?country wdt:P31/wdt:P279* wd:Q6256 .
  OPTIONAL { ?country wdt:P1082 ?population. }
  OPTIONAL { ?country rdfs:label ?countryLabel FILTER(LANG(?countryLabel) = "en") }

  {
    # Airports defined as instances (or instances of subclasses) of common airport classes
    {
      ?airport wdt:P31/wdt:P279* wd:Q1248784 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q62447 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q3631092 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q695850 .
    }

    # country assignment: direct country P17 or via admin parent chain P131*
    {
      ?airport wdt:P17 ?country .
    } UNION {
      ?airport wdt:P131* ?admin .
      ?admin wdt:P17 ?country .
    }

    # exclude airports with an end time or a dissolved/abolished/demolished date
    FILTER NOT EXISTS { ?airport wdt:P582 ?endTime. }
    FILTER NOT EXISTS { ?airport wdt:P576 ?dissolvedDate. }
  }
}
GROUP BY ?country
ORDER BY DESC(?airportCount)

SPARQL execution failed:
Invalid SPARQL query: The target ?countryLabel of an AS clause was already used in the query body.

[Assistant]
I need to fix a minor variable naming conflict (I used ?countryLabel both as an OPTIONAL variable and as the AS target). I'll re-run with the label variable named ?lab and aggregate it via SAMPLE(?lab) AS ?countryLabel, then execute the query.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?country (SAMPLE(?lab) AS ?countryLabel) (SAMPLE(?population) AS ?population) (COUNT(DISTINCT ?airport) AS ?airportCount)
WHERE {
  # restrict to countries
  ?country wdt:P31/wdt:P279* wd:Q6256 .
  OPTIONAL { ?country wdt:P1082 ?population. }
  OPTIONAL { ?country rdfs:label ?lab FILTER(LANG(?lab) = "en") }

  {
    # Airports defined as instances (or instances of subclasses) of common airport classes
    {
      ?airport wdt:P31/wdt:P279* wd:Q1248784 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q62447 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q3631092 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q695850 .
    }

    # country assignment: direct country P17 or via admin parent chain P131*
    {
      ?airport wdt:P17 ?country .
    } UNION {
      ?airport wdt:P131* ?admin .
      ?admin wdt:P17 ?country .
    }

    # exclude airports with an end time or a dissolved/abolished/demolished date
    FILTER NOT EXISTS { ?airport wdt:P582 ?endTime. }
    FILTER NOT EXISTS { ?airport wdt:P576 ?dissolvedDate. }
  }
}
GROUP BY ?country
ORDER BY DESC(?airportCount)

SPARQL execution failed:
Invalid SPARQL query: The target ?population of an AS clause was already used in the query body.

[Assistant]
I'll rename the population variable in the body to ?popVal and aggregate it as SAMPLE(?popVal) AS ?population, then execute.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?country (SAMPLE(?lab) AS ?countryLabel) (SAMPLE(?popVal) AS ?population) (COUNT(DISTINCT ?airport) AS ?airportCount)
WHERE {
  # restrict to countries
  ?country wdt:P31/wdt:P279* wd:Q6256 .
  OPTIONAL { ?country wdt:P1082 ?popVal. }
  OPTIONAL { ?country rdfs:label ?lab FILTER(LANG(?lab) = "en") }

  {
    # Airports defined as instances (or instances of subclasses) of common airport classes
    {
      ?airport wdt:P31/wdt:P279* wd:Q1248784 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q62447 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q3631092 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q695850 .
    }

    # country assignment: direct country P17 or via admin parent chain P131*
    {
      ?airport wdt:P17 ?country .
    } UNION {
      ?airport wdt:P131* ?admin .
      ?admin wdt:P17 ?country .
    }

    # exclude airports with an end time or a dissolved/abolished/demolished date
    FILTER NOT EXISTS { ?airport wdt:P582 ?endTime. }
    FILTER NOT EXISTS { ?airport wdt:P576 ?dissolvedDate. }
  }
}
GROUP BY ?country
ORDER BY DESC(?airportCount)

Got 212 rows and 4 columns, showing the first 5 and last 5 rows below:
| country                  | countryLabel            | population              | airportCount    |
| ------------------------ | ----------------------- | ----------------------- | --------------- |
| United States (wd:Q30)   | United States (lang:en) | 340110988 (xsd:decimal) | 23954 (xsd:int) |
| Australia (wd:Q408)      | Australia (lang:en)     | 26473055 (xsd:decimal)  | 2995 (xsd:int)  |
| Brazil (wd:Q155)         | Brazil (lang:en)        | 203062512 (xsd:decimal) | 2973 (xsd:int)  |
| Canada (wd:Q16)          | Canada (lang:en)        | 36991981 (xsd:decimal)  | 1765 (xsd:int)  |
| Colombia (wd:Q739)       | Colombia (lang:en)      | 52321152 (xsd:decimal)  | 910 (xsd:int)   |
| ...                      | ...                     | ...                     | ...             |
| Palestine (wd:Q219060)   | Palestine (lang:en)     | 5227193 (xsd:decimal)   | 1 (xsd:int)     |
| Andorra (wd:Q228)        | Andorra (lang:en)       | 87097 (xsd:decimal)     | 1 (xsd:int)     |
| Sint Maarten (wd:Q26273) | Sint Maarten (lang:en)  | 43847 (xsd:decimal)     | 1 (xsd:int)     |
| Monaco (wd:Q235)         | Monaco (lang:en)        | 38350 (xsd:decimal)     | 1 (xsd:int)     |
| Vatican City (wd:Q237)   | Vatican City (lang:en)  | 764 (xsd:decimal)       | 1 (xsd:int)     |

[Assistant]
answer

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?country (SAMPLE(?lab) AS ?countryLabel) (SAMPLE(?popVal) AS ?population) (COUNT(DISTINCT ?airport) AS ?airportCount)
WHERE {
  # restrict to countries
  ?country wdt:P31/wdt:P279* wd:Q6256 .
  OPTIONAL { ?country wdt:P1082 ?popVal. }
  OPTIONAL { ?country rdfs:label ?lab FILTER(LANG(?lab) = "en") }

  {
    # Airports defined as instances (or instances of subclasses) of common airport classes
    {
      ?airport wdt:P31/wdt:P279* wd:Q1248784 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q62447 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q3631092 .
    }
    UNION
    {
      ?airport wdt:P31/wdt:P279* wd:Q695850 .
    }

    # country assignment: direct country P17 or via admin parent chain P131*
    {
      ?airport wdt:P17 ?country .
    } UNION {
      ?airport wdt:P131* ?admin .
      ?admin wdt:P17 ?country .
    }

    # exclude airports with an end time or a dissolved/abolished/demolished date
    FILTER NOT EXISTS { ?airport wdt:P582 ?endTime. }
    FILTER NOT EXISTS { ?airport wdt:P576 ?dissolvedDate. }
  }
}
GROUP BY ?country
ORDER BY DESC(?airportCount)

Answer:
I executed the query that: for each country (wd:Q6256), counts distinct airports that are instances (or instances of subclasses) of airport/aerodrome/airstrip/air base, excludes airports having an end time (P582) or a dissolved/abolished/demolished date (P576), and retrieves the (direct) population value (wdt:P1082) where available. The query returns one row per country with: country IRI, English label, population (wdt:P1082 if present), and airportCount (number of operational airports as defined).

Summary of the result set: 212 countries were returned. Example rows (country label — population — airportCount):
- United States — 340110988 — 23954
- Australia — 26473055 — 2995
- Brazil — 203062512 — 2973
- Canada — 36991981 — 1765
- Colombia — 52321152 — 910

Notes, assumptions and caveats:
- Airport classes included: airport (wd:Q1248784), aerodrome (wd:Q62447), airstrip (wd:Q3631092), and air base (wd:Q695850). If you prefer a different/expanded set of classes (e.g., include military-only facilities or additional subclass types), I can adjust the query.
- Country assignment uses either wdt:P17 on the airport item or an admin-parent (wdt:P131*) whose wdt:P17 gives the country. This helps include airports whose direct P17 is missing but an admin parent has the country.
- The query excludes any airport that has a direct wdt:P582 (end time) value or wdt:P576 (dissolved/abolished/demolished date) value. Some closed facilities might instead be modeled differently on Wikidata (e.g., with statements about status) and could still appear; if you want to also exclude items with certain status properties, I can expand the filters.
- Population values are taken from wdt:P1082 (direct population value). I did not disambiguate different population statements or pick a latest point-in-time qualifier; if you need the most recent population statement with its date (pq:P585), I can rewrite the query to return the population value and its point-in-time qualifier (selecting the latest) for each country.

If you want, I can:
- Return the full table as CSV/TSV, or
- Modify the class list for airports, or
- Use the population time-series to pick the most recent population with its date.

If you want the full results now (all 212 rows) in table or CSV form, tell me which format you prefer and I will provide them.