Bucket On-Lot Vehicle Inventory by Days in Stock per Rooftop

Last updated: November 29, 2026

Quick Overview

Given a vehicles table with dealer_id, stock_type (new or used), stocked_at and a nullable sold_at, write SQL that reports, for each dealership and stock type, how many units were on the lot as of a given date in 0-30, 31-60, 61-90 and 90+ day aging buckets, plus the average age.

Tekion
Data Manipulation (SQL/Python)
Data Engineer
Tekion
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given a vehicles table with dealer_id, stock_type (new or used), stocked_at and a nullable sold_at, write SQL that reports, for each dealership and stock type, how many units were on the lot as of a given date in 0-30, 31-60, 61-90 and 90+ day aging buckets, plus the average age.

Inventory aging is one of the first reports a dealer group's used-car manager opens, because floor-plan interest makes every extra day on the lot cost money. In a Tekion-style data screen the interviewer checks that you define 'on the lot as of a date' correctly, especially for vehicles sold after that date, and produce a clean pivot.

What the Interviewer Expects
  • Defines in-stock as of a date: stocked on or before it, and unsold or sold after it
  • Computes age relative to the as-of date, not today
  • Uses conditional aggregation for buckets with non-overlapping boundaries
  • Groups by dealer and stock type and includes a total
  • Mentions how to parameterize the date for a historical snapshot
Key Topics to Cover
Conditional aggregation
Date arithmetic
Point-in-time snapshots
Inventory aging
Group by
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you produce this snapshot for every month-end of the last year in one query?
  • A vehicle transferred between two rooftops in the same group. How should its age be counted?
  • How would you compute average days-to-sale for units sold last month?
  • Wholesaled and returned units have status changes. How would you model them?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

One row per vehicle per stocking event: vin, dealer_id, stock_type, stocked_at DATE, sold_at DATE NULL. Ask whether a VIN can appear twice (sold, then reacquired as a trade-in); if so each stocking ...

Approach

First filter to vehicles physically on the lot on the as-of date. A car sold on December 5 was still on the lot on November 30, so the condition is sold_at IS NULL OR sold_at > as_of, not just `sold...


Submit Your Answer
Markdown supported

Related Questions