An airline stores passenger booking information in a table called BOOKING. BookingRef PassengerName FlightCode SeatClass BaseFare BaggageFee BK100 A. Mensah...

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

Question 1 Report

An airline stores passenger booking information in a table called BOOKING.

BookingRefPassengerNameFlightCodeSeatClassBaseFareBaggageFee
BK100A. MensahFL201Economy25030
BK101C. DuboisFL201Business6000
BK102R. TanakaFL305Economy18025
BK103L. FischerFL201Economy25030
BK104S. ObiFL305Business5200
BK105T. AndersenFL305Economy18045

(a) Write an SQL query to display the PassengerName and the total cost (BaseFare + BaggageFee) for each booking, ordered by total cost descending. [4]

Answer Details

(a) This question tests your ability to write an SQL query that performs an arithmetic calculation on columns, creates an alias for the result, and sorts the output. [4]

The query needs to:

  1. Select the PassengerName field
  2. Calculate the total cost by adding BaseFare and BaggageFee
  3. Order the results by total cost from highest to lowest
SELECT PassengerName, (BaseFare + BaggageFee) AS TotalCost
FROM BOOKING
ORDER BY TotalCost DESC

An alternative version without the alias is also acceptable:

SELECT PassengerName, BaseFare + BaggageFee
FROM BOOKING
ORDER BY (BaseFare + BaggageFee) DESC

Marking points:

  • SELECT with both PassengerName and the calculation [1]
  • BaseFare + BaggageFee as the computed expression [1]
  • ORDER BY clause present [1]
  • DESC keyword for descending order [1]

The expected output order is:

PassengerNameTotalCost
C. Dubois600
S. Obi520
A. Mensah280
L. Fischer280
T. Andersen225
R. Tanaka205

The key insight is that SQL allows arithmetic expressions in the SELECT clause. The AS keyword creates an alias so the calculated column has a meaningful name in the output. ORDER BY ... DESC sorts from largest to smallest. Business-class passengers have no baggage fee (0), so their total equals their base fare.

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning