Database coursework in T-SQL (SQL Server):
- Assignment #01 — ER diagrams (draw.io + PNG)
- Assignment #02 —
ECOMMERCEschema,BULK INSERT, 32 analytical queries on Olist - Exported CSV + chart packs for Order / Customer / Product / Seller themes
- Northwind sample DB script for extra practice
- 20 labelled feature screenshots + SSMS runbook / FK-safe load order
Author: Mohammad Rohaan · Roll: 22I-2327 · rohaan2802
Canonical script: Assignment #02/Assignment_2_i222327/Assignment #02_SQL.sql
There is no hosted web app — the “demo” is the graded SQL + exported charts. Open these directly:
Primary analysis pack (Order / Customer / Product / Seller folders):
https://github.com/rohaan2802/Data-Analysis/tree/main/Assignment%20%2302/Assignment_2_i222327
Canonical T-SQL script:
Labelled screenshot gallery:
https://github.com/rohaan2802/Data-Analysis/tree/main/docs/screenshots
Assignment #01 ER diagrams:
https://github.com/rohaan2802/Data-Analysis/tree/main/Assignment%20%2301
Northwind practice script:
https://github.com/rohaan2802/Data-Analysis/blob/main/NorthWind%20DataBase/NorthWind%20DataBase.sql
- Live demo
- Quick start
- Feature screenshots (20)
- Deep feature walkthrough
- Problem statement / academic context
- Features
- Architecture / design
- Extra docs pack
- Olist schema
- Bulk load (CSV → SQL Server)
- Analysis questions A–H
- Exported result highlights
- Assignment #01 — ER modeling
- Northwind
- Tech stack
- Project structure
- Prerequisites
- How to build and run
- Known limitations
- How to extend
- Author
- Open the Live demo links (full URLs — not “click here”).
- Skim Feature screenshots (20).
- Follow
docs/ssms-runbook.md+docs/load-order.md. - Edit every
BULK INSERT ... FROMpath in the SQL file, then execute in SSMS.
Old docs/screenshots embeds were replaced with this labelled set (optimized JPGs). Each heading is one project feature.
Assignment #01 conceptual model linking customers, orders, and core commerce entities.
Extended ER covering shipment and payment relationships.
Further section-A modeling refinements from Assignment #01.
Late deliveries (delivered_customer > estimated) by month. April peaks (1,565); July is lightest (216).
Geographic late-delivery counts. SP leads (2,387), then RJ and MG.
Which sellers show the longest mean delay (days after estimate).
Fulfillment risk by catalog segment (product_catery_name).
Mean payment_value by customer_state. PB highest (248.33); SP lowest among listed (137.50).
Customers with the highest mean purchase→delivery duration (delivered orders).
Customers ranked by canceled-order counts (assignment wording: “cancellations”).
Most profitable category (total sales) inside each customer state.
Hour-of-day with the most placements per category (e.g. bed/bath hour 14).
How average product price relates to delivered order volume.
Self-joined product pairs that co-occur on orders (product_id < product_id).
Delivered SUM(price) with PT→EN translation. Top: health_beauty, watches_gifts, bed_bath_table.
Mean review score (1–5). Tiny-n categories can show perfect 5s — interpret carefully.
Canceled item-rows / all item-rows × 100. Small sellers can hit 100% with n=1.
Sellers ranked by AVG(price) on delivered items.
(price − freight) / price. Freight is shipping, not COGS — treat as a proxy only.
SUM(freight_value) per seller on delivered items — logistics cost concentration.
Assignment #01 builds the conceptual backbone before SQL: entities, keys, and relationships for commerce (customers, orders, payments, shipping). Open .drawio in diagrams.net to edit; PNGs are the graded visuals.
Delay is defined when customer delivery is after the estimated date. Features answer: when delays peak (month), where (state), which sellers are slowest, and which categories suffer most. Uses DATEDIFF, DATEPART/MONTH, and joins through Orders → Customers / Order_Items → Products.
Spend concentration by state, delivery-time outliers, and cancellation heavy-hitters. Helps separate “many late deliveries in SP because volume is huge” from “individual customers with extreme lead times.”
Catalog intelligence: regional category winners, time-of-day demand, price–volume relationship, market-basket pairs, translated revenue leaderboard, and review quality by category. English names come from product_category_name_translation (table spelling keeps catery).
Seller health proxies: cancel rate (mislabelled “return” in the brief), average selling price, freight-based margin proxy, and total freight. Always read small-n artefacts (100% cancel with one order).
PKs/FKs/CHECKs encode domain rules: order status enum, payment types, review scores 1–5, geo lat/lng ranges, timestamp ordering (approved ≥ purchase, etc.). Several FKs use ON DELETE CASCADE.
UTF-8 BULK INSERT with FIRSTROW = 2, often TABLOCK / KEEPNULLS. Geolocation uses a staging table + ROW_NUMBER() CTE so one lat/lng survives per (zip, city, state).
Separate Microsoft sample for views/procedures practice — not joined to Olist.
Olist is a Brazilian marketplace dump: customers, sellers, orders, payments, items, reviews, products, geolocation, and Portuguese→English categories. Assignment 02: create ECOMMERCE, load CSVs, enforce integrity, dedupe geo, then answer four thematic blocks (Order / Customer / Product / Seller-and-shipment), each with questions a–h. Results live under the four *_ANALYSIS folders.
CREATE DATABASE ECOMMERCE+USE+GObatches- Tables with PKs, FKs (
ON DELETE CASCADEon several), domainCHECKs - UTF-8 bulk load (
CODEPAGE = '65001') where specified - Geolocation staging +
ROW_NUMBER()dedupe - 32 analysis
SELECTs (8 × 4 themes) - Exported CSV/PNG evidence packs
- Assignment #01 draw.io ER set
- Northwind installer script
- 20 README screenshots + docs runbook / load-order / query index
olist_*.csv ──BULK INSERT──► ECOMMERCE (SQL Server)
│
Task 1: DDL + cleaning (geo CTE, CHECKs)
│
Task 2: retrieval (Order / Customer / Product / Seller)
│
CSV + PNG exports (SSMS / Excel)
│
docs/screenshots (README gallery)
FK-safe create order: Geolocation + category translation first, then Customers / Sellers / Products, then Orders and children. Details: docs/load-order.md.
| Doc | Role |
|---|---|
docs/ssms-runbook.md |
End-to-end SSMS steps |
docs/load-order.md |
Parent/child create + load order |
docs/query-index.md |
Which a–h letters have exports |
docs/README.md |
Docs map |
LICENSE |
MIT for coursework packaging |
TREE.txt |
Layout snapshot |
Column product_catery_name spelling is intentional (matches the script + translation table).
| Table | Keys / CHECKs (from DDL) |
|---|---|
Geolocation |
PK (zip, city, state); lat/lng ranges; state length 2 |
Geolocation_Staging |
Raw load; dropped after CTE insert |
Customers |
PK customer_id; FK Geolocation CASCADE |
Sellers |
PK seller_id; FK Geolocation |
Product_Catery_Name_Translation |
PK Portuguese name → English |
Products |
PK product_id; FK category; dimension CHECKs |
Orders |
Status enum; timestamp ordering CHECKs; FK Customers CASCADE |
Order_Payments |
PK (order_id, sequential); payment-type enum |
Order_Items |
PK (order_id, item_id); FKs Orders/Products/Sellers |
Order_Reviews |
Score 1–5; answer ≥ creation when both set |
BULK INSERT Orders
FROM 'C:\PATH\TO\olist_orders_dataset.csv'
WITH (
FORMAT = 'CSV',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
FIRSTROW = 2,
CODEPAGE = '65001',
KEEPNULLS,
TABLOCK
);Replace every FROM path before running. Original machine path was C:\Users\ALLEN PROGRAMMER\Downloads\. Point at Assignment_2_i222327/ or Brazilian_Dataset/.
Geolocation dedupe pattern:
WITH UniqueGeo AS (
SELECT *, ROW_NUMBER() OVER (
PARTITION BY geolocation_zip_code_prefix, geolocation_city, geolocation_state
ORDER BY geolocation_lat, geolocation_lng
) AS rn
FROM Geolocation_Staging
)
INSERT INTO Geolocation (...)
SELECT ... FROM UniqueGeo WHERE rn = 1;This repo is SQL Server / T-SQL, not MySQL.
Wording below follows the SQL comments (including typos). Full export coverage: docs/query-index.md.
| Question | Idea | |
|---|---|---|
| a | % orders delayed beyond estimate | delivered_customer > estimated |
| b | Peak months of delays | Monthly counts |
| c | State with highest delays | Join customers, group state |
| d | Pending (processing) per year |
Status filter |
| e | Avg delay duration per seller | AVG(DATEDIFF(...)) |
| f | Shipping cost vs delays | Freight avg delayed vs on-time |
| g | Category with most delays | Count by product_catery_name |
| h | Items per order vs delays | Item aggregation delayed vs on-time |
| Question | Idea | |
|---|---|---|
| a | % one-time customers | COUNT(order_id)=1 |
| b | Top 5 cities with repeat customers | HAVING COUNT > 1 |
| c | Avg order price by state | AVG(payment_value) |
| d | Top 10 customers by order count | TOP 10 |
| e | Longest avg delivery time | AVG(DATEDIFF(...)) |
| f | Avg orders per customer per year | Orders / distinct customers |
| g | Top spenders in 2017 | Delivered + year window |
| h | Highest cancellations | order_status = 'canceled' |
| Question | Idea | |
|---|---|---|
| a | Most profitable category per state | Max SUM(price) |
| b | Peak hours per category | Hour with max count |
| c | Top 5 categories by delayed orders | With EN names |
| d | Price vs sales volume | Avg price vs counts |
| e | Bought-together pairs | Self-join |
| f | Revenue per category | Delivered SUM(price) |
| g | Avg review per category | AVG(review_score) |
| h | Top 5 products by revenue | TOP 5 SUM(price) |
| Question | Idea | |
|---|---|---|
| a | “Return” rate per seller | Cancel rate on item rows |
| b | Highest avg product price | AVG(price) |
| c | Profit margin per seller | (price − freight)/price |
| d | Shipping cost delayed vs not | Two avgs / UNION ALL |
| e | Delayed shipments in 2017 | Year filter |
| f | Freight vs delivery speed | Same comparison family as (d) |
| g | Total freight per seller | SUM(freight_value) |
From the GitHub CSV packs:
- Order B: Apr 1565 … Jul 216 delays
- Order C: SP 2387, RJ 1664, MG 638 …
- Customer C: PB ~248.33 highest mean payment; SP ~137.50
- Product F:
health_beauty~1.23M,watches_gifts~1.17M,bed_bath_table~1.02M - Seller C: head margins ~98.9% on the freight proxy (not true COGS)
DB_Assignment#1.pdf,i222327_DB_Assignment#01.docx- Tasks 1 / 3 / 5
.drawio+ PNG (screenshots 01–03)
NorthWind DataBase/NorthWind DataBase.sql — classic Microsoft installer (CREATE DATABASE Northwind, tables, views, procedures). Standalone practice DB; not linked to Olist.
SQL Server + SSMS/sqlcmd · T-SQL (BULK INSERT, CTE, DATEDIFF, TOP) · Olist CSVs · draw.io
Data-Analysis/
├── docs/screenshots/ # 20 labelled JPGs for README
├── docs/*.md # runbook, load-order, query-index
├── Assignment #01/ # ER models
├── Assignment #02/
│ ├── Assignment_2_i222327/ # SQL + CSVs + analysis packs
│ └── Brazilian_Dataset/ # duplicate Olist CSVs
├── NorthWind DataBase/
├── LICENSE · TREE.txt · README.md
SQL Server with permission to CREATE DATABASE and BULK INSERT. CSV paths must be readable by the SQL Server service account.
- Replace every
BULK INSERTpath. - Follow
docs/load-order.md(or comment FKs → load → add FKs). - Load tables; prefer
SELECT TOP 10probes. - Run Task 2; compare to analysis CSVs/PNGs and
docs/screenshots/. - Optional:
sqlcmd -S .\SQLEXPRESS -E -i "...Assignment #02_SQL.sql"after path fixes. - Optional: execute Northwind script separately.
- DDL order vs FKs — reorder creates (see load-order doc).
- Typo
caterymust stay consistent with data. - Order h uses
SUM(order_item_id)as item count (notCOUNT(*)). - Seller a is cancel rate, not returns; c is not true COGS profit.
- Only a subset of a–h queries have CSV/PNG exports.
- Hard-coded Windows paths in the submitted SQL.
- Duplicate Olist CSVs under
Brazilian_Dataset/increase clone size. - Upstream licenses: Olist dataset + Microsoft Northwind sample.
- Reorder DDL to match FKs; fix item-count to
COUNT(*); add indexes onorder_status/ delivery dates; parameterize paths withsqlcmd -v; add missing a–h export packs.
Mohammad Rohaan · Roll 22I-2327
GitHub: https://github.com/rohaan2802
Repository: https://github.com/rohaan2802/Data-Analysis



















