โ† Back to projects
๐Ÿ›’
PostgreSQL ยท SQL Analytics

Brazilian E-Commerce SQL Analysis

SQL analysis of 99,441 Brazilian e-commerce orders across 9 relational tables โ€” uncovering revenue drivers, delivery performance, seller rankings, and regional logistics gaps.

99.4K OrdersR$1.26M Top Category80% Early Deliveries1.73/5 Late Delivery Score
PostgreSQLSQLCTEsWindow FunctionsJOINsAggregations

Overview

SQL analysis of the Olist Brazilian E-Commerce dataset โ€” 99,441 orders spanning September 2016 to August 2018, stored across 9 relational tables covering orders, customers, sellers, products, payments, and reviews.

The dataset was chosen specifically because its multi-table schema mirrors real business data architecture, requiring JOINs, CTEs, and window functions to answer meaningful business questions.

Business Questions

#Question
Q1Which product categories generate the most revenue?
Q2How does delivery performance affect customer satisfaction?
Q3Who are the top-performing sellers and what sets them apart?
Q4What are the monthly order and revenue trends?
Q5Which states have the highest customer spend and worst delivery delays?

Q1 โ€” Revenue by Category

  • health_beauty is the top revenue category โ€” R$1.26M across 8,836 orders
  • watches_gifts ranks 2nd despite fewer orders โ€” highest avg item price at R$201 with only 8.3% freight-to-revenue ratio (small, high-value = efficient to ship)
  • furniture_decor carries the heaviest freight burden at 23.7% of revenue โ€” a margin risk for operations

Q2 โ€” Delivery Performance vs Customer Satisfaction

  • Orders delivered 7+ days late โ†’ avg review score of 1.73 / 5
  • Orders delivered 5+ days early โ†’ avg review score of 4.31 / 5
  • 80% of delivered orders arrived early โ€” Olist sets conservative estimates to manage expectations
  • Late delivery is the single strongest predictor of negative reviews in the dataset

Q3 โ€” Top Seller Performance

  • #1 seller (Guariba, SP) โ€” R$229,472 revenue across 1,132 orders, avg R$198.51/order, 4.12 review score
  • #2 seller (Lauro de Freitas, BA) โ€” only 358 orders but avg R$543.36/order โ€” premium product strategy outperforming high-volume sellers on revenue per order
  • Sรฃo Paulo (SP) dominates the top 20 sellers โ€” geographic concentration of the strongest merchants
  • Platform grew from 2 orders in Sep 2016 to a peak of 7,421 orders in Nov 2017 โ€” a Black Friday spike of +63.2% MoM
  • Cumulative revenue crossed R$13.5M by Aug 2018
  • Revenue dipped in early 2018 despite stable order volumes โ€” avg order value declined, suggesting a shift toward lower-value product mix

Q5 โ€” State Performance

  • Sรฃo Paulo (SP) โ€” R$5.09M revenue, 40,494 orders; nearly 3ร— the second-largest state (RJ at R$1.77M)
  • Alagoas (AL) โ€” worst delivery performance: 24.1% late delivery rate, avg 24.5 days to deliver vs SPโ€™s 8.7-day average
  • Northeast states (AL, MA, CE) consistently show higher delays and lower review scores โ€” last-mile logistics gaps

SQL Skills Used

SkillApplied In
INNER JOIN / LEFT JOINAll queries
GROUP BY + SUM, AVG, COUNTAll queries
CTE (WITH clause)Q2, Q3, Q4, Q5
CASE WHENQ2
RANK() window functionQ3, Q5
LAG() window functionQ4 โ€” MoM growth
SUM() OVER() running totalQ4 โ€” cumulative revenue
EXTRACT(EPOCH FROM ...)Q2, Q5 โ€” delivery duration
COUNT FILTER (WHERE ...)Q5 โ€” late delivery rate