Skip to content

stepjuly-pixel/e-commerce-sql-practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

E-Commerce SQL Practice Queries

Project Overview

This repository contains four independent analytical SQL queries built on a shared e-commerce database. Each query addresses a specific business question and demonstrates different SQL techniques: aggregations, joins, window functions, CTEs, UNNEST, and UNION ALL.

All queries are written in BigQuery SQL.

Tools & Technologies

  • SQL (BigQuery)

  • Window functions (SUM OVER, DENSE_RANK)

  • CTEs, UNION ALL, UNNEST

  • Conditional aggregation (CASE WHEN)

Database Schema

The database includes:

  • Transactional tables: order, product

  • Session & event data: session, session_params, event_params

  • Marketing & forecasting: paid_search_cost, revenue_predict

Queries

Query 1: Revenue by Continent

πŸ“„ View Query

For each continent, calculate total revenue, revenue from the "Bookcases & shelving units" category, and the percentage share of this category.

SQL techniques: multiple table joins, conditional aggregation with CASE WHEN, percentage calculation, GROUP BY with ORDER BY.


Query 2: Monthly Marketing Cost Share

πŸ“„ View Query

Calculate the percentage of monthly paid search costs relative to total costs across the entire period.

SQL techniques: date extraction with EXTRACT, subquery aggregation, window function SUM() OVER() for analytical percentage calculation.


Query 3: Session Engagement Rate by Device

πŸ“„ View Query

Calculate the percentage of events where session_engaged = 1 out of all events where this value is not NULL, grouped by device.

SQL techniques: CTE, working with nested fields using UNNEST, conditional counting, behavioral segmentation by device.


Query 4: Cumulative Revenue vs Target

πŸ“„ View Query

Calculate cumulative actual revenue vs cumulative predicted revenue by date and compute the percentage of target achievement.

SQL techniques: UNION ALL to combine actual and forecasted data, cumulative sums with SUM() OVER(ORDER BY date), revenue progress tracking.

How to Run

  1. Clone this repository

  2. Open any query from the sql/ folder

  3. Run in BigQuery β€” each query is independent and can be executed separately

Project Structure

e-commerce-sql-practice/
β”œβ”€β”€ sql/
β”‚   β”œβ”€β”€ query1.sql
β”‚   β”œβ”€β”€ query2.sql
β”‚   β”œβ”€β”€ query3.sql
β”‚   └── query4.sql
β”œβ”€β”€ docs/
β”‚   └── schema.png
└── README.md

About

SQL practice queries on an e-commerce database using BigQuery

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors