Project 3: Corporate Employee Hierarchy & Departmental Analytics Engine
Project 3: Corporate Employee Hierarchy & Departmental Analytics Engine
Capstone Project 3: Corporate Employee Hierarchy & Departmental Analytics Engine
Enterprise organizations are complex structures containing multi-tier managerial hierarchies, cross-departmental budgets, and salary grades.
In this capstone, you will construct a corporate data warehouse schema and deploy an Analytics Engine combining Recursive Common Table Expressions, Window Functions, and Multi-Table Aggregations to extract executive insights.
1. Database Schema & Architecture
Our schema models corporate organizational charts:
departments: Department names, locations, and annual budget caps.employees: Staff records containing salaries, department associations, and a self-referencingmanager_id.performance_reviews: Quarterly performance scores (1.0 to 5.0) evaluated over time.
2. Inserting Realistic Enterprise Seed Data
3. Executive Analytics Queries
Query 1: Complete Organizational Hierarchy Traversal (Recursive CTE)
Unroll the reporting chain from the CEO down to junior developers:
Query 2: Department Salary Benchmarking with Window Functions
Compare each employee's compensation against departmental averages and quartiles:
Query 3: Department Budget Utilization & Headcount View
Multiple Choice Questions
1. In our recursive OrgTree query, what constitutes the Anchor member?
A. The JOIN with departments table B. The query selecting employees WHERE manager_id IS NULL (the CEO) C. The UNION ALL operator D. The DENSE_RANK() window function Answer: B Explanation: The anchor member generates the initial seed row of the tree traversal by identifying the root employee who has no manager (manager_id IS NULL).
2. What does CAST(first_name AS CHAR(255)) accomplish in the Anchor member of the recursive CTE?
A. Encrypts the employee name B. Ensures the recursive string column has sufficient allocated character width to prevent string truncation during CONCAT iterations C. Converts names to lowercase D. Creates an index on first_name Answer: B Explanation: In recursive CTEs, column data types are inferred from the anchor; casting to a wide CHAR/VARCHAR prevents buffer truncation as strings grow through concat iterations.
3. Which window function was used to calculate the departmental salary ranking without skipping rank numbers for ties?
A. ROW_NUMBER() B. DENSE_RANK() C. RANK() D. NTILE() Answer: B Explanation: DENSE_RANK() assigns sequential ranks to ordered rows without gaps or skips when duplicate salaries occur.
4. What does the expression salary - AVG(salary) OVER(PARTITION BY dept_id) calculate?
A. The company's total annual tax obligation B. The difference between an employee's salary and their department's average compensation C. The employee's net take-home pay D. The remaining departmental budget Answer: B Explanation: This window expression subtracts the department's partitioned average salary from the individual employee's salary to show variance.
5. Why is ON DELETE SET NULL appropriate for the manager_id foreign key constraint?
A. It deletes all employees if the CEO resigns B. If a manager departs, their direct reports' manager_id becomes NULL rather than deleting the employees C. It forces all staff to report to human resources D. It prevents managers from receiving salary increases Answer: B Explanation: ON DELETE SET NULL ensures that removing a supervisor record does not cascade-delete their subordinates; instead, subordinates simply have their manager_id temporarily set to NULL.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Project 2: Banking Transaction & Ledger System with ACID Guarantees | None |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.