An intermediate-to-advanced SQL analytics project applying window functions, CTEs, views, customer segmentation, and revenue leaderboards to an online food delivery platform dataset.
Level: π‘ Advanced | Status: β Complete | Part: 2 of 3
Data visualisations and dashboards built from this project are available via Power BI / Google Sheets / Excel. Screenshots are in the
/Screenshotsfolder.
Having established foundational metrics in Project 1, this project goes deeper β answering strategic business questions that require advanced SQL techniques. Businesses need more than just counts and sums; they need to understand customer loyalty, restaurant rankings, menu dead weight, and time-based behavioural patterns.
Goal: Apply advanced SQL analytics to the online food delivery dataset to produce actionable business intelligence β including customer classification, restaurant revenue rankings, trend analysis, and reusable database objects for reporting.
Why this project? This is the second project in a 3-part SQL portfolio series, bridging beginner SQL and a full enterprise analytics system. It demonstrates proficiency in:
- Window functions (
RANK(),ROW_NUMBER(),SUM OVER) - Conditional logic with
CASE WHENfor business segmentation - Reusable database objects: temporary tables and views
- Connecting SQL outputs to visualisation tools (Power BI / Excel / Google Sheets)
Challenges faced:
- Designing CASE WHEN logic that accurately reflects real business classification rules
- Using window functions correctly to rank restaurants without losing other columns
- Identifying "never ordered" menu items requires understanding LEFT JOIN and NULL filtering
- Building views and temp tables that are efficient enough for repeated use in reporting
This project uses the same 5 relational tables as Project 1:
| Table | Description |
|---|---|
Customers |
Customer details including signup dates and city |
Orders |
Transaction records with order date and customer ID |
Menu_Items |
List of food items offered by restaurants with pricing |
Order_Details |
Line-item breakdown of items ordered per transaction |
Restaurants |
Restaurant information including city and menu offerings |
Customers ββ< Orders ββ< Order_Details >ββ Menu_Items
β
Restaurants
- Customer signup year β Early Bird / Regular / New classification
- Order frequency per customer β Loyal vs one-time customer detection
- Menu item order counts β Dead stock identification (never ordered items)
- Restaurant menu size β Small / Medium / Large categorisation
- Revenue per restaurant β Leaderboard with window functions
Future enhancements:
- Automate customer reclassification as new orders come in (trigger logic in Project 3)
- Add delivery performance metrics (covered in Project 3)
- Expand the revenue leaderboard into a live Power BI dashboard
Visualisation outputs (Power BI / Excel / Google Sheets) and query result screenshots are in the
/Screenshotsfolder.
| Tool | Purpose |
|---|---|
| MySQL 8.x | Relational database engine β window functions, CTEs, views |
| VS Code | Primary development IDE |
| SQLTools Extension | MySQL connection and query execution within VS Code |
| SQLTools MySQL/MariaDB Driver | VS Code driver to connect to MySQL server |
| MySQL Workbench | Backend MySQL server (connected via SQLTools) |
| Power BI / Google Sheets / Excel | Data visualisation of query outputs |
| Git & GitHub | Version control and project showcase |
- MySQL Server installed and running (port 3306)
- VS Code with SQLTools + MySQL Driver installed
- (Optional) Power BI Desktop or Google Sheets for visualisations
git clone https://github.com/BuragapalliKamachari/online-food-delivery-sql-project-2.git
cd online-food-delivery-sql-project-2- Open VS Code β Click the SQLTools icon in the Activity Bar
- Select Add New Connection β Choose MySQL
- Enter connection details:
- Host:
localhost - Port:
3306 - Username:
root - Password: (your MySQL root password)
- Host:
- Click Test Connection β Save
1. Database_Creation.sql β Use existing DB from Project 1 or recreate
2. Table_Creation.sql β Ensure all 5 tables exist with data
3. Advanced_Analysis.sql β Run all 10 advanced problem statements
4. Views_TempTables.sql β Create views and temporary tables
5. Revenue_Leaderboard.sql β Window function leaderboard queries
- Export query results as CSV from SQLTools
- Import into Power BI / Google Sheets / Excel
- Build charts for monthly trends, revenue rankings, and customer segments
This project follows the Data Analysis Lifecycle: Define β Collect β Analyse β Model β Visualise β Report.
| # | Problem Statement | SQL Technique |
|---|---|---|
| 1 | Classify customers by signup year (Early Bird / Regular / New) | CASE WHEN, YEAR() |
| 2 | Identify customers with maximum orders | COUNT, ORDER BY, LIMIT |
| 6 | Detect one-time customers | HAVING COUNT(*) = 1 |
Customer Classification Logic:
CASE
WHEN YEAR(signup_date) <= 2020 THEN 'Early Bird'
WHEN YEAR(signup_date) BETWEEN 2021 AND 2022 THEN 'Regular'
ELSE 'New'
END AS customer_category| # | Problem Statement | SQL Technique |
|---|---|---|
| 3 | Rank restaurants by revenue performance | RANK(), Window Functions |
| 7 | Categorise restaurants by menu size (Small/Medium/Large) | CASE WHEN, COUNT |
| 9 | Build revenue leaderboard | SUM() OVER, RANK() OVER |
Restaurant Size Classification Logic:
CASE
WHEN menu_item_count < 10 THEN 'Small'
WHEN menu_item_count BETWEEN 10 AND 20 THEN 'Medium'
ELSE 'Large'
END AS restaurant_size| # | Problem Statement | SQL Technique |
|---|---|---|
| 4 | Find menu items never ordered | LEFT JOIN, WHERE IS NULL |
| 5 | Monthly and weekly order trends | MONTH(), WEEK(), GROUP BY |
| # | Object | Purpose |
|---|---|---|
| 8 | Temporary Tables | Store intermediate results for complex multi-step analysis |
| 8 | Views | Create reusable virtual tables for reporting and dashboards |
| 10 | Visualisation Export | Connect SQL outputs to Power BI / Google Sheets / Excel |
- Monthly trend charts (line chart β orders over time)
- Revenue leaderboard (bar chart β top restaurants)
- Customer segment distribution (pie chart β Early Bird / Regular / New)
β
Complete β Jan 2026
This is Part 2 of 3 in the Online Food Delivery SQL Portfolio Series:
- β Project 1 β Beginner Analysis
- β Project 2 β Advanced Analytics β You are here
- π Project 3 β Business Analytics System (In Progress)
| Contributor | Role |
|---|---|
| Buragapalli Kamachari | Project Author β Advanced SQL Development & Analytics |
| MySQL Documentation | Reference for window functions, CTEs, and views |
| SQLTools by Matheus Teixeira | VS Code MySQL integration extension |
| Power BI / Google / Microsoft | Visualisation platforms used for reporting |
| GitHub | Repository hosting and portfolio showcase |
Online Food Delivery SQL Project 2 of 3 | Buragapalli Kamachari | Jan 2026