
Surge share by city
easySurge share by city
Lyft SQL Interview Question
Lyft's pricing team tracks how often riders in each city see surge pricing, meaning a multiplier above 1.0.
For each city, return the number of ride requests as requests and the percentage of requests with surge pricing as surge_pct, rounded to 1 decimal place. Sort by surge_pct, highest first.
Asked of
- Data Analyst
- Business Analyst
- BI Analyst
- Product Analyst
- Analytics Engineer
ride_requestsTable22 rows
| Column Name | Type |
|---|---|
| request_id | BIGINT |
| city | VARCHAR |
| requested_at | TIMESTAMP |
| surge_multiplier | DOUBLE |
ride_requestsExample Input
| request_id | city | requested_at | surge_multiplier |
|---|---|---|---|
| 1 | San Francisco | 2024-09-06 08:05:00 | 1 |
| 2 | Chicago | 2024-09-06 07:45:00 | 1 |
| 3 | San Francisco | 2024-09-06 08:20:00 | 1.2 |
| 4 | Miami | 2024-09-06 21:10:00 | 1 |
| 5 | San Francisco | 2024-09-06 17:40:00 | 1.5 |
| 6 | Chicago | 2024-09-06 17:05:00 | 1.3 |
| 7 | Miami | 2024-09-06 22:15:00 | 1.4 |
| 8 | San Francisco | 2024-09-06 08:45:00 | 1.2 |
| 9 | Chicago | 2024-09-06 17:30:00 | 1.3 |
| 10 | Miami | 2024-09-06 22:40:00 | 1.6 |
| 11 | San Francisco | 2024-09-06 18:10:00 | 1.1 |
| 12 | Chicago | 2024-09-06 08:15:00 | 1 |
| 13 | Miami | 2024-09-06 22:55:00 | 1.8 |
| 14 | San Francisco | 2024-09-07 08:30:00 | 1 |
| 15 | Chicago | 2024-09-07 17:50:00 | 1.2 |
| 16 | Miami | 2024-09-07 13:05:00 | 1 |
| 17 | San Francisco | 2024-09-07 17:15:00 | 1.4 |
| 18 | Chicago | 2024-09-07 12:00:00 | 1 |
| 19 | Miami | 2024-09-07 22:20:00 | 1.5 |
| 20 | Miami | 2024-09-07 21:45:00 | 1.1 |
| 21 | Chicago | 2024-09-07 07:10:00 | 1 |
| 22 | San Francisco | 2024-09-07 12:25:00 | 1 |
Example Output
| city | requests | surge_pct |
|---|---|---|
| Miami | 7 | 71.4 |
| San Francisco | 8 | 62.5 |
| Chicago | 7 | 42.9 |
Explanation
San Francisco had 8 requests, and 5 of them had a multiplier above 1.0, so its surge share is 62.5. Requests with a multiplier of exactly 1.0 are normal price and do not count as surge.
The example above is a small slice of the data. Your query runs against the full tables.
Company
Lyft
Difficulty
easy
Topic
conditional logic
Language
SQL
Your query
Starting the SQL engine...