[SQL] “Bikes last used” – Lyft

Lyft SQL Interview

Photo from Markus Spiske on Pexels


The dataset for this SQL interview question from Lyft and Doordash contains information on some rental bikes. These information include the rental duration, the starting time, starting station, end station, bike number and so on.

The goal here would be to write a query which will sort the bike numbers based on their most recent usages. 

Here is the solution to this puzzle:

 

SELECT bike_number, MAX(end_time) "last_used"
FROM dc_bikeshare_q1_2012
GROUP BY bike_number
ORDER BY last DESC

 

You can find the full explanation of the puzzle and its solution here:

 

Related Images: