SQL
Lab
Uber Uber Interview Question 07

Most Popular
Pickup
Location

Find the most common pickup location.

Table Schema

Inspect
Table

interactive
ColumnType
trip_idinteger
pickup_locationvarchar

Sample Data

Input
Output

Sample Input: trips
trip_idpickup_location
1A
2B
3A
4C
5A
6B
7A
Expected Output
pickup_locationtrips
A4

SQL Editor

Run
Query

postgresql
Waiting for query

pickup_locationtrips
A4

Hints

Unlock
Clues

Hint 01: Identify the grouping level required by the output.
Hint 02: Aggregate with COUNT, SUM, AVG, or a window function as needed.
Hint 03: Filter after aggregation with HAVING or after ranking with an outer query.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT pickup_location, COUNT(*) AS trips
FROM trips
GROUP BY pickup_location
ORDER BY trips DESC
LIMIT 1;

Explanation

Step By
Step

01

Read the expected output columns to determine the final grain.

02

Aggregate or rank the input rows to calculate the requested metric.

03

Filter, sort, and alias the final columns to match the output.

Related Questions

Keep
Solving