项目作者: ArchanaRohilla

项目描述 :
Employees Database Management & Analysis using SQL and pgAdmin
高级语言:
项目地址: git://github.com/ArchanaRohilla/Pewlett-Hackard-Analysis.git
创建时间: 2020-02-25T00:54:56Z
项目社区:https://github.com/ArchanaRohilla/Pewlett-Hackard-Analysis

开源协议:

下载


Pewlett Hackard Employees Database Management and Analysis

Project Overview

In this project, Database analysis for the employees eligible for the retirement has been carried out. The retirement criterion was that the birth date of the
employee should be between 1952 and 1955. And also the employee should be hired between 1985 and 1988.

Tools

SQL, PostgreSQL, pgAdmin

Summary

  • Number of individuals retiring: There are 33118 current employees which are retiring as per the above criterion.

  • Number of individuals being hired: The number of individuals being hired should be ideally equal to the number of retirees (i.e.33118). But there should also be
    some criterion for hiring as well.

  • Number of individuals available for mentorship role: There are 1549 employees who are eligible for mentorship role.The mentorship criterion was that the employee should be born
    in year 1965.

  • Recommendation for further analysis on this data set: There should be some criterion for hiring individuals as well. Because with the change of time and the technology enhancement
    or automation the company requirement changes. Also the current salary should be updated in the database after the employees’s
    promotion.

Entity Relationship Diagram:

alt text

Code for the Queries

List of (titles) retiring employees

  1. SELECT ce.emp_no,
  2. ce.first_name,
  3. ce.last_name,
  4. ti.title,
  5. ti.from_date,
  6. s.salary
  7. INTO titles_retirees
  8. FROM current_emp as ce
  9. INNER JOIN titles as ti
  10. ON (ce.emp_no = ti.emp_no)
  11. INNER JOIN salaries as s
  12. ON (ce.emp_no = s.emp_no);
  13. --Refer to titles_retirees.csv in Data folder.
  14. SELECT * FROM titles_retirees;

List of Only the Most Recent Titles

  1. --List of retirees with their titles in decending order as per from_date column
  2. SELECT *,
  3. ROW_NUMBER() OVER (PARTITION BY first_name, last_name ORDER BY from_date DESC) AS r_num
  4. INTO titles_order
  5. FROM titles_retirees
  6. ORDER BY emp_no ASC;
  7. SELECT * FROM titles_order;
  8. --Partition the data to show only most recent title per employee
  9. --List of retirees with their current titles
  10. SELECT
  11. emp_no, first_name, last_name, title, from_date, salary
  12. INTO titles_current
  13. FROM titles_order
  14. WHERE r_num=1;
  15. --Refer to titles_current.csv in Data folder.
  16. SELECT * FROM titles_current;

List of the title count

  1. SELECT emp_no, first_name, last_name, title, from_date, salary,
  2. COUNT(emp_no) OVER (PARTITION BY title) AS t_count
  3. INTO count_titles
  4. FROM titles_current
  5. ORDER BY emp_no ASC;
  6. SELECT * FROM count_titles;
  7. --List of the frequency count of employee titles.
  8. SELECT DISTINCT title,t_count
  9. INTO titles_count
  10. FROM count_titles;
  11. --Refer to titles_count.csv in Data folder.
  12. SELECT * FROM titles_count;

List of employees who are ready for Mentorship

  1. SELECT
  2. e.emp_no,
  3. e.first_name,
  4. e.last_name,
  5. ti.title,
  6. ti.from_date,
  7. de.to_date
  8. INTO mentor_table
  9. From employees as e INNER JOIN titles as ti ON (e.emp_no = ti.emp_no)
  10. INNER JOIN dept_emp as de ON (e.emp_no = de.emp_no)
  11. WHERE e.birth_date BETWEEN '1965-01-01' AND '1965-12-31'
  12. AND de.to_date = '9999-01-01';
  13. SELECT * FROM mentor_table;

List of mentors with their current titles

  1. with my_table as (
  2. SELECT *, row_number() OVER (Partition By first_name, last_name Order by from_date desc) as r_num
  3. FROM mentor_table)
  4. Select *
  5. INTO mentor_table_uniquified
  6. From my_table where r_num = 1
  7. Select emp_no, first_name, last_name, title,from_date,to_date
  8. INTO mentors_current
  9. from mentor_table_uniquified
  10. ORDER BY emp_no ASC;
  11. --Refer to mentors_current.csv in Data folder.
  12. SELECT * FROM mentors_current;