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_idINTEGERrider_idINTEGERdriver_idINTEGERsurge_multiplierREALfare_amountREALtrip_statusVARCHAR(20)
riders
rider_idINTEGERfirst_nameVARCHAR(50)last_nameVARCHAR(50)
drivers
driver_idINTEGERfirst_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_idWhy 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_id | rider_name | driver_name | surge_multiplier | fare_amount |
|---|---|---|---|---|
| 1002 | Bob Baker | Jane Smith | 1.5 | 45 |
| 1004 | Daniel Davis | Sarah Williams | 1.2 | 55 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Airbnb
Independent Airbnb-style marketplace, booking, listing, payment, review, and guest analytics SQL practice.
Amazon
Independent Amazon-style e-commerce, warehouse, inventory, and customer analytics SQL practice.
Google
Independent Google-style search, advertising, user-engagement, and video-product SQL practice.
Return to the complete interview preparation experience.