Exploratory data analysis on a real-world e-commerce dataset using SQL and DataCamp DataLab.
This project answers key business questions around revenue, customer behavior, product performance, and data quality.
E-Commerce-SQL-Analysis/
├── analysis.sql ← all 10 SQL queries
└── README.md
Source: UCI Machine Learning Repository — Online Retail
Transnational transaction data from a UK-based online retailer (December 2010 – December 2011).
~541,000 rows · 8 columns
| Column | Description |
|---|---|
| InvoiceNo | Invoice number (prefix C = cancellation) |
| StockCode | Product code |
| Description | Product name |
| Quantity | Units per transaction |
| InvoiceDate | Date and time of invoice |
| UnitPrice | Price per unit (GBP £) |
| CustomerID | Unique customer identifier (nullable) |
| Country | Country of customer residence |
- Which countries generate the most revenue?
- Who are the top customers?
- What products sell the most?
- How much customer data is missing?
- How does revenue trend month over month?
| # | Query | Description |
|---|---|---|
| 01 | Explore the data | Preview first 10 rows of the dataset |
| 02 | Total row count | Verify total number of records |
| 03 | Missing CustomerIDs | Count rows with no customer identifier |
| 04 | Clean dataset | Filter nulls and invalid transactions |
| 05 | Sales by country | Total revenue grouped by country |
| 06 | Top customers | Top 10 customers ranked by total spend |
| 07 | Best-selling products | Top 10 products by quantity sold |
| 08 | Missing data by country | Null CustomerID rate per country |
| 09 | Monthly revenue trend | Month-over-month revenue and order count |
| 10 | Average order value | Average spend per order by country |
- United Kingdom dominates total sales, contributing the vast majority of revenue
- A small number of customers drive a disproportionately large share of total spend
- A significant percentage of transactions have missing CustomerIDs, particularly from certain countries, which limits customer-level analysis
- Revenue shows a clear upward trend toward Q4, reflecting seasonal demand peaks
- The top 10 best-selling products are predominantly gift and home décor items
All queries are written in DuckDB SQL and run on DataCamp DataLab.
Dates in the CSV follow the format MM/DD/YY HH:MM — parsed using:
FROM read_csv('online_retail.csv',
header = true,
timestampformat = '%m/%d/%y %H:%M'
)Data cleaning applied across all analysis queries:
- Removed rows where
CustomerID IS NULL - Excluded rows where
Quantity <= 0(returns/cancellations) - Excluded rows where
UnitPrice <= 0(invalid pricing)
DataCamp DataLab
- Open DataCamp DataLab
- Add E-Commerce Data as a data source
- Copy queries from
analysis.sqlinto a SQL cell and run
DuckDB CLI
pip install duckdb
duckdb
.read analysis.sql| Tool | Purpose |
|---|---|
| SQL | Data querying and analysis |
| DuckDB | In-process analytical SQL engine |
| DataCamp DataLab | Cloud SQL notebook environment |
| GitHub | Version control and portfolio hosting |
swezinye
GitHub Profile