This repository contains a curated set of SQL scripts taken from real production systems. The goal is to demonstrate practical, operational SQL patterns rather than isolated examples or academic exercises.
The scripts have been sanitized to remove proprietary identifiers while preserving structure, logic, and design decisions.
/analytics
/operational
- analytics: Data warehouse, ELT, and reporting-oriented SQL patterns
- operational: System-level views, functions, and decision-support logic used by applications
These scripts focus on transforming raw or transactional data into structures suitable for reporting, analysis, and performance measurement.
-
Average Inventory View
Calculates average inventory levels between snapshots using a standard financial method. -
Concurrent Usage / Interval Analysis
Buckets activity into fixed time intervals to analyze concurrent usage over time. -
Date & Time Dimensions
Builds reusable calendar and time dimensions for dimensional modeling. -
Item Load & Pareto Processing
Loads item data and recalculates classifications used for reporting and prioritization. -
Activity / History Log Processing
Transforms event logs into structured activity-time metrics for analytics.
These scripts support live operations, application behavior, and decision-making logic.
-
Order Pickability Query
Determines whether orders are fully pickable using running totals and zone grouping. -
Inventory Availability Views
Combines multiple inventory states into a single consumable view. -
Replenishment Logic Functions
Calculates when and where inventory replenishment is required based on configurable rules. -
Order Summary Views
Aggregates line-level order details into order-level operational summaries. -
Publication / Slotting Logic
Groups and slots records into fixed output templates based on business constraints.
Across all scripts, the following principles are emphasized:
- Defensive SQL design for imperfect or evolving data
- Reusable views and functions instead of one-off queries
- Performance-aware use of window functions and aggregation
- Business-rule-driven modeling rather than purely technical schemas
These scripts are intended as reference implementations and are not expected to run as-is without supporting schema and data.