This project demonstrates database creation, table setup, data insertion, and SQL querying using PostgreSQL with psql.
-
schema.sql : SQL script to create 4 tables:
- customers
- products
- orders
- order_items
-
insert_data.sql : SQL script to insert 10 rows into each table.
-
query_screenshots/ : Folder containing screenshots of query results.
- Get all customers from the East region
- List products over $100, sorted by price (descending)
- Show top 3 products by price
- Show customers in alphabetical order
Screenshots of each query's output are saved inside the query_screenshots/ folder.
This task focuses on applying SQL filters and conditions to retrieve meaningful business data from the database.
- filters_queries.sql : SQL script containing 5 business queries using filters and conditions.
- query_screenshots/ : Folder containing screenshots of query results.
- Identify customers who haven't placed any orders
- Find top 5 most expensive products
- List all distinct product categories
- Find all orders placed in the last 30 days
- Show customers whose names start with 'A' or 'B'
This task focuses on using SQL aggregation functions and grouping techniques to generate business reports from database tables.
- aggregations.sql : SQL script containing 5 grouped reports using aggregation functions.
- query_screenshots/ : Folder containing screenshots of query results.
- Total sales (SUM of total_amount) by region
- Count of orders placed per customer
- Average product price per product category
- Top 3 customers ranked by total spend
- List of products never sold (zero quantity in order_items)
Identify the top 3 regions generating the highest total revenue in the past month to guide targeted marketing strategies
This task demonstrates the use of SQL JOINs to fetch combined data from multiple tables and analyze relational dependencies between entities.
- joins_queries.sql : SQL script containing multi-table JOIN queries.
- query_screenshots/ : Folder containing screenshots of each query output.
- Brief explanations of JOIN behaviors included as SQL comments inside the SQL script.
-
Fetch Order Details:
- Display Order ID, Customer Name, Product Name, and Quantity.
-
Identify Data Issues:
- Find orders linked to missing products or invalid customers using OUTER JOIN techniques.
-
Customer Order Summary:
- List all customers with their total number of orders.
-
Product Order Counts:
- Show each product with the number of times it has been ordered (aggregate JOIN report).
-
JOIN Comparison:
- Compare results of INNER JOIN vs LEFT JOIN between Customers and Orders to illustrate missing data handling.
This task focuses on using subqueries and Common Table Expressions (CTEs) to perform complex multi-step data analysis using PostgreSQL.
- subqueries.sql : SQL script containing 5 analytical queries using subqueries and/or CTEs.
- query_screenshots/ : Folder containing screenshots of each query output.
-
Customers Who Ordered Premium Products
- Find customers who have ordered products priced above the average product price.
-
Unsold Products Report
- Show products that were never ordered.
-
Repeat Customers
- Identify customers who have placed more than one order.
-
Large Orders Analysis
- List orders that contain more than 3 products.
-
High-Spending North Region Customers
- From customers in the "North" region, list those whose total spend is above the regional average.
- Scalar Subqueries
- IN and EXISTS
- Correlated Subqueries
- Common Table Expressions (CTEs) using
WITH - Nested filtering and modular SQL design
- Subqueries (inline & correlated) help in step-wise data filtering inside WHERE, SELECT, and FROM clauses.
- CTEs (WITH clause) simplify complex multi-stage queries and improve modularity.
- Encourages reusable and readable SQL code.