TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #2598 2.25K
๐Ÿš€ SQL Project Series #9

HR Analytics Project ๐Ÿ‘จโ€๐Ÿ’ผ

Analyze employee data to understand workforce trends, employee performance, attrition, hiring, salaries, and organizational health using SQL.

๐ŸŽฏ Business Objectives

โœ… Analyze employee demographics

โœ… Measure employee attrition

โœ… Track hiring trends

โœ… Analyze salaries and compensation

โœ… Evaluate department performance

โœ… Monitor attendance and leave patterns

โœ… Identify high-performing employees

โœ… Generate HR dashboards

๐Ÿ“‚ Step 1: Create Database

CREATE DATABASE hr_analytics_db;

USE hr_analytics_db;


๐Ÿ“‚ Step 2: Create Departments Table

CREATE TABLE departments (
department_id INT PRIMARY KEY,
department_name VARCHAR(100)
);


๐Ÿ“‚ Step 3: Create Employees Table

CREATE TABLE employees (
employee_id INT PRIMARY KEY,
employee_name VARCHAR(100),
gender VARCHAR(10),
age INT,
department_id INT,
designation VARCHAR(100),
salary DECIMAL(10,2),
hire_date DATE,
city VARCHAR(50),
employment_status VARCHAR(20),
FOREIGN KEY (department_id)
REFERENCES departments(department_id)
);


๐Ÿ“‚ Step 4: Create Attendance Table

CREATE TABLE attendance (
attendance_id INT PRIMARY KEY,
employee_id INT,
attendance_date DATE,
status VARCHAR(20),
FOREIGN KEY (employee_id)
REFERENCES employees(employee_id)
);


๐Ÿ“‚ Step 5: Create Performance Table

CREATE TABLE performance (
review_id INT PRIMARY KEY,
employee_id INT,
review_year INT,
performance_rating DECIMAL(3,2),
bonus DECIMAL(10,2),
FOREIGN KEY (employee_id)
REFERENCES employees(employee_id)
);


๐Ÿ“‚ Step 6: Insert Sample Departments

INSERT INTO departments VALUES
(1,'Engineering'),
(2,'Human Resources'),
(3,'Finance'),
(4,'Sales'),
(5,'Marketing');


๐Ÿ“‚ Step 7: Insert Sample Employees

INSERT INTO employees VALUES
(101,'Rahul Sharma','Male',30,1,'Software Engineer',85000,'2022-01-15','Mumbai','Active'),
(102,'Priya Verma','Female',28,4,'Sales Executive',65000,'2023-03-10','Delhi','Active'),
(103,'Amit Patel','Male',35,3,'Financial Analyst',92000,'2021-06-20','Pune','Active'),
(104,'Sneha Joshi','Female',31,2,'HR Manager',78000,'2020-11-12','Bangalore','Active'),
(105,'Rohan Gupta','Male',29,5,'Marketing Specialist',70000,'2024-02-01','Hyderabad','Resigned');


๐Ÿ“‚ Step 8: Insert Sample Attendance

INSERT INTO attendance VALUES
(1,101,'2025-01-01','Present'),
(2,102,'2025-01-01','Present'),
(3,103,'2025-01-01','Absent'),
(4,104,'2025-01-01','Present'),
(5,105,'2025-01-01','Leave');


๐Ÿ“‚ Step 9: Insert Sample Performance Data

INSERT INTO performance VALUES
(1,101,2024,4.8,20000),
(2,102,2024,4.3,12000),
(3,103,2024,4.9,25000),
(4,104,2024,4.5,18000),
(5,105,2024,3.9,10000);
  • โค 3
More from @sqlanalyst
  1. Oct 8, 2026๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ Upgrโ€ฆ
  2. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  3. Oct 7, 2026SQL Interview Series โ€” Part 4 ๐Ÿ“Œ Question 4: Find the Highest Salary in Each Department Suโ€ฆ
  4. Oct 7, 2026๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ Learn Power BI through these FREE learninโ€ฆ
  5. Sep 29, 2026SQL Interview Series โ€” Part 2 ๐Ÿ“Œ Question 2: Find Duplicate Records Suppose you have an Emโ€ฆ
  6. Sep 29, 2026๐—™๐—ฅ๐—˜๐—˜ ๐—ฅ๐—ฒ๐˜€๐—ผ๐˜‚๐—ฟ๐—ฐ๐—ฒ๐˜€ ๐—ง๐—ผ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป ๐—”๐—œ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ๐Ÿš€ โ€‹ Explore 6 free resourceโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’