Uber-style Company ChallengeEasyVerified answerSQLite live

Trips in Surge Pricing

Which completed trips had surge pricing applied, and what were the surge multiplier and fare?

  • Joins
  • Filtering
  • Sorting

Challenge brief

Understand the request

Dynamic Pricing Team is auditing surge pricing events to validate that multipliers were applied correctly on completed rides.

List completed trips where surge_multiplier > 1.0 with rider name, driver name, surge multiplier, and fare.

Return

  • trip_id
  • rider_name (full name)
  • driver_name (full name)
  • surge_multiplier
  • fare_amount

Constraints

  • Return completed trips with a surge multiplier above 1.0
  • Order by surge multiplier descending, then trip ID

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

trips

  • trip_idINTEGER
  • rider_idINTEGER
  • driver_idINTEGER
  • surge_multiplierREAL
  • fare_amountREAL
  • trip_statusVARCHAR(20)

riders

  • rider_idINTEGER
  • first_nameVARCHAR(50)
  • last_nameVARCHAR(50)

drivers

  • driver_idINTEGER
  • first_nameVARCHAR(50)
  • last_nameVARCHAR(50)

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

Trips with surge pricing have surge_multiplier > 1.0. Rider and driver names come from separate JOIN paths — trips connects to both riders and drivers via rider_id and driver_id respectively.

Hint 2

INNER JOIN trips to riders on rider_id, and to drivers on driver_id. WHERE trip_status = 'completed' AND surge_multiplier > 1.0. ORDER BY surge_multiplier DESC.

Hint 3

Join each qualifying trip to its rider and driver labels, apply both business filters, and finish with a stable trip-level order.

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT t.trip_id, r.first_name || ' ' || r.last_name AS rider_name, d.first_name || ' ' || d.last_name AS driver_name, t.surge_multiplier, t.fare_amount FROM trips t INNER JOIN riders r ON t.rider_id = r.rider_id INNER JOIN drivers d ON t.driver_id = d.driver_id WHERE t.trip_status = 'completed' AND t.surge_multiplier > 1.0 ORDER BY t.surge_multiplier DESC, t.trip_id

Why this works

Four of six trips have surge_multiplier = 1.0 (no surge). Two qualify: trip 1002 (1.5x) and trip 1004 (1.2x). Both INNER JOINs are needed to get both the rider and driver names from the same trips row.

Success check

2 surge trips — Bob Baker at 1.5x ($45) and Daniel Davis at 1.2x ($55)

Expected result

Use this output to verify values, aliases, ordering, and row count.

trip_idrider_namedriver_namesurge_multiplierfare_amount
1002Bob BakerJane Smith1.545
1004Daniel DavisSarah Williams1.255

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Interview Practice

Return to the complete interview preparation experience.