⚡0 XP🔥0

Module Project: Business Analysis with SQL

Lesson 8 of 8 ⏱ 4 min read ✎ 5 exercises ❓ 3-question quiz ▶ Runs SQL

Answer real management questions on the shop database with auto-checked SQL, then analyse the real Olist Brazilian e-commerce database from Kaggle (100k orders) in DB Browser for SQLite.

Project brief#

The management of the online shop wants a business review. You must answer their questions with SQL, check your numbers, and write short insights.

Use the editor below to explore. Each question in Practice Exercises is checked automatically against the correct result.

▶ Try it Yourselfdatabase: shopSQL
Ctrl + Enter to run
हिंदी में समझें

इस project में आप एक business analyst की तरह management के सवालों के जवाब SQL से निकालेंगे। हर सवाल का जवाब नीचे के exercises में अपने-आप जाँचा जाएगा।

तरीका: पहले tables समझें → सवाल को छोटे कदमों में तोड़ें (CTE) → हर कदम का नतीजा जाँचें → फिर अंतिम query लिखें → और आखिर में insight लिखें (नतीजा + इसका मतलब + सुझाव)।

Questions from management#

# Question Exercise
1 How many delivered orders, how much revenue, and what's the average order value? Q1
2 Which 3 cities generate the most revenue? Q2
3 Which payment modes have the highest cancellation/return rate? Q3
4 Which category is most profitable (margin %)? Q4
5 Who are our most loyal customers? Q5

Your checklist#

  • [ ] Define revenue clearly (we use Delivered orders, after discount).
  • [ ] Use COUNT(DISTINCT order_id) after joining order_items.
  • [ ] Verify one number another way (e.g. revenue total = sum of category revenues).
  • [ ] Write one insight per question.
Sample insights (check after solving)
  • Q1: 156 delivered orders, revenue ≈ Rs. 21.2 lakh, AOV ≈ Rs. 13,598.
  • Q2: Nagpur, Bhubaneswar and Lucknow lead - none of them metro cities. Insight: tier-2 cities deserve marketing attention.
  • Q3: Cash has the highest problem rate (≈ 16.7%); UPI, Card and COD are around 10-11%. Net Banking shows 0%, but with only 11 orders - be careful drawing conclusions from small samples.
  • Q4: Office Supplies ≈ 39% margin, Furniture ≈ 25%, Technology ≈ 10% - Technology brings revenue, others bring profit. Bundle accessories with phones/laptops.
  • Q5: 26 customers have ordered 5 or more times - most of the active base. A loyalty programme for them protects the majority of repeat revenue.

Now the real thing - Olist e-commerce database (Kaggle)#

Kaggle - E-commerce dataset by Olist (SQLite)

Link: kaggle.com/datasets/terencicp/e-commerce-dataset-by-olist-as-an-sqlite-database

Real data from Olist, a Brazilian e-commerce marketplace - about 100,000 orders (2016-2018) with customers, sellers, products, payments, reviews and geolocation, imported into a single SQLite file olist.sqlite (~113 MB). The original CSV version is at kaggle.com/datasets/olistbr/brazilian-ecommerce.

Setup (10 minutes)#

  1. Download and unzip olist.sqlite from the link above (free Kaggle account needed).
  2. Install DB Browser for SQLite (free, Windows/Mac/Linux) → Open Database → choose olist.sqlite.
  3. Open the Database Structure tab - list the tables and note the key columns (order_id, customer_id, product_id, seller_id).
  4. Open the Execute SQL tab to write queries.
Tip

Large tables: always start with SELECT * FROM table LIMIT 10; to see the columns before writing big queries.

Olist SQL tasks

Write one query per task, save them in a file olist_analysis.sql, and note each answer:

  1. How many orders are there per order_status?
  2. How many orders per month (use the purchase timestamp)? Which month had the most?
  3. Top 10 product categories by total item price.
  4. Average delivery time in days (delivered date - purchase date) by customer state. Which states wait longest?
  5. Share of payments by payment type, and the average number of instalments for credit cards.
  6. Average review score by product category - which categories have the lowest scores (minimum 100 reviews)? Use HAVING.
  7. Top 10 sellers by revenue, with their number of orders and average review score (joins across 3-4 tables).
  8. Use a window function to rank categories by revenue within each year.
  9. Month-on-month order growth % with LAG.
  10. Write 5 insights for Olist management (finding + why it matters + action).
Common Mistake

Column and table names in the Olist SQLite file may differ from the original CSV names (the uploader shortened them). Always check the Database Structure tab first.

Summary#

  • Break business questions into small, verifiable SQL steps.
  • State metric definitions (e.g. revenue = delivered orders after discount).
  • Watch the grain after joins; verify numbers two ways.
  • Practise on a real 100k-order database to become interview-ready.

Practice Exercises

Write your code, then press Check. Your program is tested automatically.

1

Q1: KPI summary

For Delivered orders, show one row with: orders (distinct orders), revenue (rounded to 2 decimals) and avg_order_value (revenue ÷ orders, rounded to 2 decimals).

Database: shop (see the tables in this lesson)
2

Q2: Top 3 cities by revenue

Show the top 3 customer city values by Delivered revenue (rounded to 2 decimals), highest first.

Database: shop (see the tables in this lesson)
3

Q3: Problem-order rate by payment mode

For each payment_mode, show orders and problem_pct = % of orders that were Cancelled or Returned (rounded to 1 decimal). Sort by problem_pct descending, then payment_mode.

Database: shop (see the tables in this lesson)
4

Q4: Profit margin by category

For Delivered orders, show each category, revenue and margin_pct = profit ÷ revenue × 100 (rounded to 1 decimal), where profit per item = quantity × (price × (1 - discount) - cost). Sort by margin_pct descending.

Database: shop (see the tables in this lesson)
5

Q5: Loyal customers

Find customers whose number of orders is 5 or more. Show name, orders, first_order (earliest order_date) and last_order (latest), sorted by orders descending then name.

Database: shop (see the tables in this lesson)

Quick Quiz

Q1.

Before writing a complex query, what should you do first?

Q2.

How do you check that a join didn't duplicate rows?

Q3.

Which metric should exclude cancelled and returned orders?