SQL-Data Analytcs
SQL-Data Analytcs
1. Data Retrieval
- Basic Queries:
- Selecting Data:
- Filtering Data:
- Using `WHERE`:
- Combining Conditions:
SELECT * FROM sales_data WHERE sales_amount > 1000 AND region = 'North America';
- Sorting Data:
2. Data Aggregation
- Aggregating Data:
- Grouping Data:
FROM sales_data
GROUP BY region;
Groups data by `region` and calculates total sales for each region.
- Using `HAVING`:
FROM sales_data
GROUP BY region
3. Data Joins
- Inner Join:
- Combining Tables:
FROM sales_data
Retrieves data combining information from `sales_data` and `products` tables based on a common
key.
- Left Join:
Retrieves all records from `sales_data` and matched records from `products`.
4. Data Transformation
- Creating Views:
- Defining a View:
FROM sales_data
- Inserting Data:
- Inserting Records:
- Updating Data:
- Updating Records:
UPDATE sales_data
- Deleting Data:
- Deleting Records:
5. Data Analysis
- Subqueries:
- Using Subqueries:
SELECT product_name
FROM sales_data
Retrieves products with sales amounts greater than the average sales amount.
- Window Functions:
FROM sales_data;
Assigns a rank to each product within its region based on sales amount.
- Defining a CTE:
WITH RegionalSales AS (
FROM sales_data
GROUP BY region
Uses a CTE to simplify complex queries by breaking them into manageable parts.
6. Data Reporting
- Generating Reports:
FROM sales_data
GROUP BY region;
FROM sales_data
GROUP BY product_name
Retrieves the total and average sales per product, sorted by total sales.
- Customer Segmentation:
FROM orders
GROUP BY customer_id
Segments customers based on their total spending, showing those who spent over $1000.
Campaign Effectiveness:
- Campaign ROI:
FROM campaign_data
GROUP BY campaign_name;
2. Finance
Financial Reporting:
- Profit and Loss Statement:
FROM financials
GROUP BY department;
Budget Analysis:
- Budget vs. Actual:
FROM budget_data
GROUP BY budget_category;
FROM balance_sheet
GROUP BY company;
3. Operations
FROM inventory_data
GROUP BY product_id;
Measures how quickly inventory is sold and replaced for each product.
Production Efficiency:
- Machine Downtime Analysis:
FROM machine_data
GROUP BY machine_id
Quality Control:
- Defect Rates:
FROM quality_data
GROUP BY product_line;
4. HR Analytics
Employee Performance:
- Performance Review Summary:
FROM employee_reviews
GROUP BY department;
Attrition Analysis:
- Employee Turnover:
FROM employee_data
GROUP BY department;
Compensation Analysis:
- Salary Analysis:
FROM employee_salaries
GROUP BY job_title;
FROM sales_data
GROUP BY date;
FROM cash_flow
GROUP BY month;
Operations:
- Supplier Performance:
FROM orders
GROUP BY supplier_id;
HR Analytics:
- Training Effectiveness:
FROM training_data
GROUP BY training_program;
Measures the effectiveness of training programs by comparing pre- and post-training scores.
SQL provides the backbone for querying, analyzing, and managing data across various domains, making
it essential for data-driven decision-making and reporting.