Skip to content

ub-victor/plsql-window-functions-ushindi-Victoire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

61 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

plsql-window-functions-Ushindi-Victoire

πŸ“‘ Table of Contents


πŸ“˜ Course Information

  • Course: Database Development with PL/SQL (INSY 8311) β€” Mastery Project
  • Student: Ushindi Bihame Victoire
  • Instructor: Eric Maniraguha
  • Date: 25 Sep - 29 Sep 2025

πŸ“Œ Business Problem

The project analyzes customer and product performance using PL/SQL window functions:

  • Identify top products and customers.
  • Quantify monthly sales trends & running totals.
  • Measure growth over time.
  • Segment customers into quartiles for marketing.
  • Compute moving averages for forecasting inventory.

πŸ‘‰ Helps business improve marketing and inventory management decisions.


πŸ—„οΈ Database Schema

Tables

  • customers β†’ customer_id, name, region, created_at
  • products β†’ product_id, name, category
  • transactions β†’ transaction_id, customer_id, product_id, sale_date, quantity, amount

Constraints & Indexes

  • Primary keys on all tables.
  • Foreign keys: transactions.customer_id β†’ customers, transactions.product_id β†’ products.
  • Indexes on sale_date, customer_id, product_id.

πŸ—‚οΈ ER Diagram

erDiagram
    CUSTOMERS {
        int customer_id PK
        text name
        text region
        date created_at
    }

    PRODUCTS {
        int product_id PK
        text name
        text category
    }

    TRANSACTIONS {
        int transaction_id PK
        int customer_id FK
        int product_id FK
        date sale_date
        int quantity
        numeric amount
    }

    CUSTOMERS ||--o{ TRANSACTIONS : "purchases"
    PRODUCTS  ||--o{ TRANSACTIONS : "sold in"
Loading

πŸ“‚ Repository Structure

plsql-window-functions-Ushindi-Victoire/
β”œβ”€β”€ schema/
β”‚   └── schema_and_sample_data.sql   # Tables + sample inserts
β”œβ”€β”€ queries/
β”‚   β”œβ”€β”€ 01_ranking.sql               # Query A - Ranking
β”‚   β”œβ”€β”€ 02_aggregate_running_total_A.sql  # Query B1 - Running total (ROWS)
β”‚   β”œβ”€β”€ 02_aggregate_running_total_B.sql  # Query B2 - Running total (RANGE)
β”‚   β”œβ”€β”€ 03_navigation_lag_lead.sql   # Query C - Month-over-Month growth
β”‚   β”œβ”€β”€ 04_distribution_ntile_cume_dist.sql # Query D - Quartiles & CUME_DIST
β”‚   β”œβ”€β”€ 05_moving_avg.sql            # Query E - Moving averages
β”‚   └── revenue_analysis.sql         # Revenue queries (top quartile etc.)
β”œβ”€β”€ analysis/
β”‚   └── analysis.md                  # Descriptive + prescriptive insights
β”œβ”€β”€ screenshots/                     # Query execution results
β”œβ”€β”€ references.md                    # References & academic integrity
β”œβ”€β”€ LICENSE.txt                      # MIT License
└── README.md                        # Project overview

βš™οΈ How to Run

  1. Create database plsql_window_db in pgAdmin 4 (or use VS Code with PostgreSQL extension).
  2. Run schema/schema_and_sample_data.sql to create tables and load data.
  3. Execute queries inside queries/ to reproduce results.
  4. Compare results with screenshots in screenshots/.

πŸ”‘ Key Queries

  • Ranking: ROW_NUMBER(), RANK(), DENSE_RANK(), PERCENT_RANK() β†’ top customers.
  • Aggregate: SUM(), AVG(), MIN(), MAX() with ROWS & RANGE frames β†’ trends & totals.
  • Navigation: LAG(), LEAD() β†’ month-over-month growth.
  • Distribution: NTILE(4), CUME_DIST() β†’ segment customers into quartiles.
  • Moving averages: AVG() OVER() β†’ 3-month rolling average.
  • Revenue analysis: total revenue, quartiles, % of top 25% contribution.

πŸ“Š Key Findings

  1. Top 25% of customers contributed ~52.94% of revenue β†’ loyalty program recommended.
  2. Seasonal spikes in April & June β†’ plan inventory ahead.
  3. Coffee Beans 1kg dominates sales β†’ allocate more stock to this product.

πŸ“œ Academic Integrity

All sources are cited in references.md.
All queries and analysis are original.
No AI-generated text/code copied without attribution.


πŸ“˜ Contribution Guidelines

  • Use uppercase SQL keywords & consistent formatting.
  • Add documentation when introducing new queries.
  • Include screenshots for new query results.
  • Follow MIT License rules.

πŸš€ Clone and Explore

git clone https://github.com/ub-victor/plsql-window-functions-ushindi-Victoire.git
cd plsql-window-functions-ushindi-Victoire

πŸ™Œ Credits

  • Assignment by Lecturer Eric Maniraguha
  • Developed by Ushindi Bihame Victoire
  • GitHub: ub-victor

πŸ“œ License

This project is licensed under the MIT License.
See LICENSE.txt for details.