create view MealFlightDetails (FlightId, FlightNumber, Origin, Destination, MealId,
         Protein, Side, Salad, Snack, MealType, SeatClass, Quantity, Served, Remaining) as
    select flight.id, flight.flightnumber, departureAirport.code, arrivalAirport.code,
           meal.id, meal.protein, meal.side,
           meal.salad, meal.snack, mealtype.name, seatclass.name,servedmeals.quantity,
           servedmeals.served, servedmeals.quantity - servedmeals.served
    from flight
    join servedmeals on flight.id = servedmeals.flightid
    join meal on servedmeals.mealid = meal.id
    join mealtype on meal.mealtypeid = mealtype.id
    join gate as departureGate on departureGate.id = flight.actualgatedepartureid
    join gate as arrivalGate on arrivalGate.id = flight.actualgatearrivalid
    join terminal as departureTerminal on departureTerminal.id = departureGate.terminalid
    join terminal as arrivalTerminal on arrivalTerminal.id = arrivalGate.terminalid
    join airport as departureAirport on departureAirport.id = departureTerminal.airportid
    join airport as arrivalAirport on arrivalAirport.id = arrivalTerminal.airportid
    join seatclass on meal.seatclassid = seatclass.id;
