select
b.flight_booking_seq ,
p.title,
p.first_name as firstName,
p.last_name as lastName,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'A'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') as guestSeat ,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'C'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') as childSeat ,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'I'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') as infantSeat ,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'A'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') +
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'C'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') as seat ,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'A'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') +
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'C'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') +
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'I'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') as allSeat ,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'A'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'R') as guestSeatReturn ,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'C'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') as childSeatReturn ,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'I'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') as infantSeatReturn ,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'A'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') +
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'C'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') as seatReturn ,
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'A'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') +
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'C'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') +
( select count(p.passenger_type)
from ka_flight_passenger p
where p.passenger_type = 'I'
and p.flight_booking_seq = '29538'
and fi.itinerary_type = 'D') as allSeatReturn ,
b.round_trip as roundTrip,
s.flight_sche_seq as flightSeq,
convert(varchar, s.flight_date, 103) as flightDate ,
f.flight_from as flightFrom,
( select rt.route_name from ka_route rt
where rt.route_code = f.flight_from ) as flightFromName,
f.flight_To as flightTo,
( select rt.route_name from ka_route rt
where rt.route_code = f.flight_to ) as flightToName ,
f.flight_no as flightNo,
s.price as price,
f.flight_dep as depTime,
f.flight_arr as arrTime
from ka_flight_passenger p,ka_flight_booking b , ka_flight_sche s right join ka_flight_itinerary fi
on fi.flight_sche_seq = s.flight_sche_seq left join ka_flight f
on s.flight_no = f.flight_no
where b.flight_booking_seq = '29542'
and p.flight_booking_seq = b.flight_booking_seq
and b.flight_booking_seq = fi.flight_booking_seq
and fi.flight_sche_seq = s.flight_sche_seq
and fi.itinerary_type = 'D'
--ORDER BY fi.itinerary_type