A SQL project analyzing 2,000 retail transactions (Jan 2022 – Dec 2023) to answer real business questions about sales, customers, and product categories.
A SQL project analyzing retail transaction data to answer business questions about sales, customers, and category performance. Built in MySQL.
Table: RETAIL_SALES_ANS in the RETAIL_SALES database.
| Column | Description |
|---|---|
| transaction_id | Unique transaction ID |
| sale_date, sale_time | When the sale happened |
| customer_id, gender, age | Customer info |
| category, quantity | What was bought, how much |
| price_per_unit, cogs, total_sales | Pricing and revenue |
1. Create the database and table
CREATE DATABASE RETAIL_SALES;
USE RETAIL_SALES;
CREATE TABLE RETAIL_SALES_ANS(
TRANSACTION_ID INT,
SALE_DATE DATE,
SALE_TIME TIME,
CUSTOMER_ID INT,
GENDER VARCHAR(10),
AGE INT,
CATEGORY VARCHAR(20),
QUANTITY INT,
PRICE_PER_UNIT FLOAT,
COGS FLOAT,
TOTAL_SALES FLOAT
);Data was then imported into this table.
2. Clean the data
Checked every column for nulls, then deleted any incomplete rows before analysis — a single missing total_sales or quantity would skew the aggregations.
SELECT * FROM RETAIL_SALES_ANS
WHERE TRANSACTION_ID IS NULL OR SALE_DATE IS NULL OR SALE_TIME IS NULL
OR CUSTOMER_ID IS NULL OR GENDER IS NULL OR AGE IS NULL
OR CATEGORY IS NULL OR QUANTITY IS NULL OR PRICE_PER_UNIT IS NULL
OR COGS IS NULL OR TOTAL_SALES IS NULL;
DELETE FROM RETAIL_SALES_ANS
WHERE TRANSACTION_ID IS NULL OR SALE_DATE IS NULL OR SALE_TIME IS NULL
OR CUSTOMER_ID IS NULL OR GENDER IS NULL OR AGE IS NULL
OR CATEGORY IS NULL OR QUANTITY IS NULL OR PRICE_PER_UNIT IS NULL
OR COGS IS NULL OR TOTAL_SALES IS NULL;3. Explore the basics Before jumping into business questions, got a feel for the data's scale:
SELECT COUNT(*) AS TOTAL_NO_SALES FROM RETAIL_SALES_ANS;
SELECT COUNT(DISTINCT CUSTOMER_ID) AS UNIQUE_CUSTOMERS FROM RETAIL_SALES_ANS;
SELECT COUNT(DISTINCT CATEGORY) AS UNIQUE_CATEGORY FROM RETAIL_SALES_ANS;4. Answer business questions
Full queries are in RETAIL_SALES_ANS.sql.
- Sales made on
2022-11-05 - Clothing transactions with quantity ≥ 3 in Nov 2022
- Total sales per category
- Average customer age for the Beauty category
- Transactions with total sale > 1000
- Transaction count by gender within each category
- Average monthly sale, with the best-selling month per year (using
RANK()) - Top 5 customers by total sales
- Unique customers per category
- Repeat customers with 5+ transactions
- Most profitable category (Total Sales − COGS)
- A small set of customers account for repeat purchases at volume (5+ transactions), pointing to a loyal core buyer base.
- Category-level profit tells a different story than raw sales once COGS is factored in.
- Sales aren't flat across the year — certain months consistently outperform others, and this varies year to year.
git clone https://github.com/<your-username>/<repo-name>.gitRun the setup and cleaning steps in RETAIL_SALES_ANS.sql against a MySQL instance, then run the 11 analysis queries.