PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates SQL competencies in aggregation, filtering, joins, numeric formatting, and precise date-based age calculation, including handling NULL fares, canceled trips, leap-year birthdays, and boundary-age cases.

  • Medium
  • Uber
  • Data Manipulation (SQL/Python)
  • Data Scientist

Write SQL for fares and age-band counts

Company: Uber

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: Medium

Interview Round: Technical Screen

You have two tables. Schema: - drivers(driver_id VARCHAR PRIMARY KEY, name VARCHAR, date_of_birth DATE) - trips(trip_id VARCHAR PRIMARY KEY, driver_id VARCHAR, trip_date DATE, trip_fare_dollars DECIMAL(10,2), trip_status VARCHAR) Sample data: drivers | driver_id | name | date_of_birth | |-----------|----------|---------------| | D1 | Jane Doe | 1996-03-14 | | D2 | Mark S | 1963-09-16 | | D3 | Adam L | 1965-05-19 | | D4 | Jaime L | 1976-05-19 | trips | trip_id | driver_id | trip_date | trip_fare_dollars | trip_status | |---------|-----------|------------|-------------------|-------------| | T1 | D1 | 2019-01-01 | 17.52 | completed | | T2 | D1 | 2019-01-02 | 4.40 | completed | | T3 | D1 | 2019-01-03 | NULL | canceled | | T4 | D2 | 2019-01-01 | 25.00 | completed | | T5 | D3 | 2019-01-01 | 8.00 | completed | | T7 | D2 | 2019-01-02 | NULL | canceled | Write SQL (one query or two CTEs is fine) to: (a) Return driver names whose average fare over completed trips is strictly greater than 10.00. Exclude non-completed trips and rows where trip_fare_dollars IS NULL. Output columns: driver_name, avg_fare_2dp (rounded to 2 decimals). Order by avg_fare_2dp DESC, then driver_name ASC. Drivers with zero completed trips must not appear. (b) Count completed trips by driver age bands as of 2025-09-01. Use inclusive boundaries for bands: 20–35 and 36–45 (i.e., ages in [20,35] and [36,45]). Compute age from date_of_birth accurately (no 365-day approximation). Output two rows with columns: age_band ('20-35' or '36-45'), total_completed_trips. Ignore drivers outside 20–45. Edge cases to handle: null fares, canceled trips, drivers without completed trips, leap-year birthdays, and band boundary birthdays on 2025-09-01.

Quick Answer: This question evaluates SQL competencies in aggregation, filtering, joins, numeric formatting, and precise date-based age calculation, including handling NULL fares, canceled trips, leap-year birthdays, and boundary-age cases.

Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Transform DataFrame and compute diff-in-diff - Uber (easy)
  • Write SQL for active counts and YTD top driver - Uber (Medium)
  • Write SQL and Pandas for Uber Trips - Uber (Medium)
  • Compute ETA shift and conversion uplift - Uber (Medium)
  • Write SQL/Python for CTR analytics - Uber (Medium)