This project demonstrates basic data analysis using PostgreSQL with a sample sales database.
The analysis includes:
- Customer data
- Product catalog
- Sales transactions
- 8 analytical queries for business insights
- customers - Customer information (name, email, city, signup date)
- products - Product catalog (name, category, price)
- sales - Transaction records (customer, product, quantity, date, amount)
Make sure PostgreSQL is installed on your system.
# Connect to PostgreSQL
psql -U your_username
# Create and use the database
CREATE DATABASE sales_db;
\c sales_db
# Run the analysis script
\i sales_analysis.sqlOr run it directly:
psql -U your_username -d sales_db -f sales_analysis.sqlShows total sales, quantity, and revenue for each product category.
Identifies the highest-spending customers.
Tracks revenue and order patterns over time.
Lists products by units sold and revenue generated.
Geographic analysis of sales performance.
Analyzes customer behavior and lifetime value.
Statistical summary of product pricing by category.
Calculates average customer value in each location.
After running the queries, you'll be able to answer questions like:
- Which product category generates the most revenue?
- Who are our most valuable customers?
- What's the sales trend over recent months?
- Which cities have the highest customer value?
- What products are bestsellers?
You can modify the script to:
- Add more sample data
- Create additional analysis queries
- Add indexes for performance
- Include more complex JOIN operations
- Add date range filters
- Create views for commonly used queries
- PostgreSQL 12 or higher
- Basic SQL knowledge
- Command line or pgAdmin access
- Run the script to create the database and tables
- Execute the analysis queries one by one
- Modify queries to explore different aspects of the data
- Add your own data or queries for practice
- All monetary values are in USD
- Sample data covers January-April 2024
- The database uses SERIAL for auto-incrementing IDs
- Foreign key constraints maintain referential integrity