create materialized view TicketRevenueDetails (FLightId, FLightNumber, FlightCapacity, TicketsSold,
    TicketBasePriceTotal, TicketFinalPriceTotal) as
    select flight.id, flight.flightnumber, airplanemodel.numberofseats,
           count(ticket.id), sum(ticket.baseprice), sum(ticket.finalprice)
    from flight
    join ticket on flight.id = ticket.flightid
    join airplane on flight.airplaneid = airplane.id
    join airplanemodel on airplane.modelid = airplanemodel.id
    group by flight.id, flight.flightnumber, airplanemodel.numberofseats;

