SQL Server T-SQL Exploratory Analysis Used Car Market

BMW Used Cars
SQL Analysis

Exploratory data analysis of 10,000+ BMW used car listings — uncovering pricing anomalies, ownership costs, depreciation patterns, and transmission trends using Microsoft SQL Server.

Tool
SQL Server (SSMS)
Dataset
Kaggle — BMW
Period
1996 – 2020
Author
Kehinde Odewabi
10,781
Car Listings
24
BMW Models
24yrs
Data Span
7
Analysis Sections
01 — Objective

What Makes a BMW Cheap to Own?

The used car market is full of traps — low sticker prices that hide high running costs, and high-mileage cars priced as if brand new. This project uses T-SQL in Microsoft SQL Server to cut through the noise across 10,781 BMW listings, answering seven core questions about pricing, tax, depreciation, mileage, transmission, engine size, and fuel efficiency.

The central question: which BMW models offer the best value — not just at purchase, but over years of ownership?

02 — Price Anomalies

Anomalies & Outliers

Before any analysis, the data was interrogated for anomalies — cars priced inconsistently with their age and mileage. Two queries surface the outliers:

A. Older Cars Priced Unusually High

T-SQL — Top 20 Most Expensive
SELECT TOP 20 model, [year], price
FROM Bmw
ORDER BY price DESC

B. Low Mileage Cars Priced Unusually Low

T-SQL — Low Mileage, Low Price
SELECT TOP 20 model, [year], price, mileage
FROM Bmw
ORDER BY mileage ASC

Low-mileage cars priced at the bottom of the market are candidates for further investigation — potential data errors, fleet vehicles, or genuine bargains worth isolating.

03 — Tax & Ownership Cost

Cheapest Models to Own

Road tax is a recurring annual cost. Combined with purchase price, it gives a clearer picture of long-term ownership expense than price alone.

Average Tax by Model

T-SQL — Avg Tax per Model
SELECT model, AVG(tax) Tax
FROM Bmw
GROUP BY model
ORDER BY Tax ASC
ModelAvg Annual TaxVerdict
i3£38Cheapest to tax — electric advantage
i8£80Hybrid efficiency reflected in tax
1 Series£109Lowest among petrol/diesel models
M3£326Performance tax premium
M6£508Most expensive to tax annually

10-Year Ownership Cost

By multiplying annual tax by 10 and adding purchase price, a true long-term cost emerges:

T-SQL — 10-Year Total Cost
SELECT TOP 20 model, [year], tax, price,
       (price + (tax * 10)) [Total Cost]
FROM Bmw
GROUP BY model, [year], tax, price
ORDER BY [Total Cost]
04 — Transmission Analysis

Transmission Trends Over Time

Which transmission type dominates each year — and is that shifting over time? A subquery with RANK() isolates the most common transmission per year without guessing alphabetically.

T-SQL — Dominant Transmission Per Year (Subquery + RANK)
SELECT [year], transmission AS [Highest Transmission],
       [Transmission Count]
FROM
  (
    SELECT [year], transmission,
           COUNT(transmission) [Transmission Count],
           RANK() OVER(PARTITION BY [year]
                        ORDER BY COUNT(transmission) DESC) AS [Rank]
    FROM Bmw
    GROUP BY [year], transmission
  ) AS [Transmission Figures]
WHERE [Rank] = 1
ORDER BY [year]

The same RANK logic is applied by model (section 4B) to find each model's most common transmission type — giving a cleaner answer than MAX(transmission), which returns the alphabetically last value rather than the most frequent.

05 — Depreciation

Which Models Hold Their Value?

Depreciation is calculated by comparing the highest and lowest average prices per model across years — a subquery pattern that produces a single depreciation figure per model:

T-SQL — Total Depreciation Per Model
SELECT model,
       MIN(Avg_Price) AS Lowest_Price,
       MAX(Avg_Price) AS Highest_Price,
       MIN(Avg_Price) - MAX(Avg_Price) AS Total_Depreciation
FROM (
  SELECT model, [year], AVG(price) AS Avg_Price
  FROM Bmw
  GROUP BY model, [year]
) AS yearly_prices
GROUP BY model
ORDER BY Total_Depreciation ASC
📉

Fastest Depreciating

£117K

2 Series loses the most value across its price range — followed by M4 (£73K) and 3 Series (£71K).

🏆

Best Value Retention

£11K

Z3 and i3 hold value best — depreciating only £11K across their full range on the used market.

Electric Advantage

£38

i3 has the lowest annual tax at just £38 — and among the lowest depreciation. Best long-term value case.

06 — Fuel Type & Efficiency

Diesel vs Petrol vs Electric

Fuel type drives both running costs and resale value. The data shows a clear efficiency and tax hierarchy:

Fuel TypeAvg Annual TaxAvg MPGTakeaway
Electric£45470.8Lowest tax, highest efficiency
Hybrid£82156.9Strong efficiency, moderate tax
Diesel£12057.8Best everyday fuel economy
Petrol£16142.9Higher tax, lower efficiency

Diesel pays 25% less tax than petrol on average — a significant saving over multiple years. Electric and Hybrid models cut that further but come at a higher purchase price.

07 — Key Findings

What the Data Reveals

Cheapest to Own Long-Term

The i3 wins on every ownership cost metric: lowest annual tax (£38), lowest depreciation, and highest fuel efficiency.

Diesel Beats Petrol on Cost

Diesel averages £41 less per year in road tax than petrol, and 15 more miles per gallon — a meaningful saving over 5–10 years.

M-Series: Buy for Fun, Not Value

M3 and M6 carry the highest tax burden and depreciate significantly. Best for performance buyers, not value-conscious ones.

Automatic Dominates

Automatic transmission is the most common type across nearly every model year — a trend that strengthens noticeably post-2010.


Project Files

View the full SQL script and raw dataset below. Upload your GitHub link once the repo is live.