The final part of the series, Hopper Company Queries III interview question, asks for a 3-month rolling average of ride distance and ride duration for each month from January to October 2020. Specifically, for month , you calculate the average of (month , , and ). This is a classic "Moving Average" problem applied to a relational database schema.
Uber uses this to test proficiency with Window Functions and complex temporal windows. Calculating a moving average is a standard task in financial and operational analytics. It evaluations whether a candidate can use the OVER clause with specific ROWS or RANGE frames to aggregate data across a shifting boundary of rows.
This problem uses Monthly Aggregation followed by a Rolling Window Function.
AVG() OVER() window function.BETWEEN CURRENT ROW AND 2 FOLLOWING.
PRECEDING instead of FOLLOWING, or including only 2 months total.Moving averages are a "Tier 1" SQL concept. Master the ROWS BETWEEN X PRECEDING AND Y FOLLOWING syntax. It is the most efficient way to perform trend analysis in databases without writing expensive self-joins.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Hopper Company Queries I | Hard | Solve | |
| Hopper Company Queries II | Hard | Solve | |
| Human Traffic of Stadium | Hard | Solve | |
| Trips and Users | Hard | Solve | |
| Analyze Organization Hierarchy | Hard | Solve |