-3

This shows the average occupancy (num_pax) of flights that have an airport of "SPAIN" as an exit

How can I convert this for PostgreSQL please?

SELECT AVG(number_pax) 
FROM flights f,airports a 
WHERE f.departure_airport=a.id_airport
AND a.country LIKE "ESPAÑA";
jmunsch
  • 19,902
  • 9
  • 82
  • 102
Miguel
  • 9
  • 2

1 Answers1

2

Your immediate issue is that Postgres uses double quotes for identifiers. You want to use the standard single quotes instead (that you should be using anyway).

I would also warmly recommend to use proper, explicit joins instead of old-school, implicit joins.

Finally, your LIKE condition has no joker character on the right side, so it is equivalent to an equality check.

SELECT AVG(number_pax) 
FROM flights f
INNER JOIN airports a ON f.departure_airport = a.id_airport
WHERE a.country = 'ESPAÑA';
GMB
  • 195,563
  • 23
  • 62
  • 110