PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Write SQL for car rental utilization by city

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in SQL querying and relational data modeling, focusing on time-interval overlap logic, distinct aggregation across joined tables, null handling, and safe computation of utilization metrics.

  • hard
  • Meta
  • Coding & Algorithms
  • Data Engineer

Write SQL for car rental utilization by city

Company: Meta

Role: Data Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

## SQL / Data Query Prompt (Car Rental) You are given four tables: ### `user` - `user_id` ### `location` - `location_id` - `city` ### `car` - `car_id` - `car_size` (e.g., compact, midsize, suv) - `location_id` (the car’s current/home location) - `is_active` (1 if available in fleet) ### `fct_rental` - `rental_id` - `car_id` - `pickup_location_id` - `pickup_ts` - `dropoff_ts` (nullable if not yet returned) ## Task For a given date `D` (e.g., `'2025-01-15'`), compute for **each (city, car_size)**: 1. `rented_cars`: how many **distinct cars** were **rented at any time during date D** (i.e., the rental interval overlaps that date). 2. `inventory_cars`: how many cars of that `car_size` exist in that city’s inventory (based on `car.location_id`, only `is_active = 1`). 3. `utilization_rate = rented_cars / inventory_cars` (as a decimal). Return rows grouped by `city` and `car_size`. ### Notes - A rental overlaps date D if it started before the end of D and ended after the start of D. Treat `dropoff_ts` NULL as "still ongoing". - If `inventory_cars = 0`, return `utilization_rate` as NULL (or avoid division-by-zero).

Quick Answer: This question evaluates proficiency in SQL querying and relational data modeling, focusing on time-interval overlap logic, distinct aggregation across joined tables, null handling, and safe computation of utilization metrics.

Related Interview Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
Meta logo
Meta
Dec 1, 2025, 12:00 AM
Data Engineer
Onsite
Coding & Algorithms
10
0

SQL / Data Query Prompt (Car Rental)

You are given four tables:

user

  • user_id

location

  • location_id
  • city

car

  • car_id
  • car_size (e.g., compact, midsize, suv)
  • location_id (the car’s current/home location)
  • is_active (1 if available in fleet)

fct_rental

  • rental_id
  • car_id
  • pickup_location_id
  • pickup_ts
  • dropoff_ts (nullable if not yet returned)

Task

For a given date D (e.g., '2025-01-15'), compute for each (city, car_size):

  1. rented_cars : how many distinct cars were rented at any time during date D (i.e., the rental interval overlaps that date).
  2. inventory_cars : how many cars of that car_size exist in that city’s inventory (based on car.location_id , only is_active = 1 ).
  3. utilization_rate = rented_cars / inventory_cars (as a decimal).

Return rows grouped by city and car_size.

Notes

  • A rental overlaps date D if it started before the end of D and ended after the start of D. Treat dropoff_ts NULL as "still ongoing".
  • If inventory_cars = 0 , return utilization_rate as NULL (or avoid division-by-zero).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Data Engineer•Meta Data Engineer•Meta Coding & Algorithms•Data Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.