/pewlett_hackard

This project involves utilizing SQL to conduct data modeling, engineering, and analysis on historical employee records.

Primary LanguagePLpgSQLMIT LicenseMIT

          This Project discusses an exploration on the people database who employed at Pewlett Hackard (a fictional company) during the 1980s and 1990s. There are only six CSV records remaining in the employee database from that period.

1. Data Modeling

          Entity-Relationship Diagrams (ERD) was used as basic modeling technique in this project. This technique was performed using QUICK DBD app. ERD identified six employee database entities such as $\space \mathsf{\color{purple}Employees}$, $\space \mathsf{\color{purple}Department} \space \mathsf{\color{purple}Employees}$, $\space \mathsf{\color{purple}Department} \space \mathsf{\color{purple}Managers}$, $\space \mathsf{\color{purple}Salaries}$, $\space \mathsf{\color{purple}Titles}$, $\space \mathsf{\color{purple}Department}$. The result of the modeling was drawn in figure [1]. Also, Pewlett Hackard ERD Documentation is presented the details of this diagram.

Fig[1] Entity-Relationship Diagrams

2. Data Engineering

Create a Table and Import Data

3. Data Analysis

  1. List the employee number, last name, first name, sex, and salary of each employee
SELECT e.emp_no, e.last_name, e.first_name, e.sex, s.salary
FROM employees e JOIN salaries s ON e.emp_no = s.emp_no;
  1. List the first name, last name, and hire date for the employees who were hired in 1986
SELECT  e.first_name, e.last_name, e.hire_date
FROM employees e 
WHERE e.hire_date BETWEEN '1986-1-1' AND '1986-12-31';
  1. List the manager of each department along with their department number, department name, employee number, last name, and first name
SELECT d.dept_no,d.dept_name, e.emp_no, e.last_name, e.first_name
FROM department d 
JOIN department_managers dm ON d.dept_no = dm.dept_no
JOIN employees e ON dm.emp_no=e.emp_no;
  1. List the department number for each employee along with that employee’s employee number, last name, first name, and department name
SELECT e.emp_no, e.last_name, e.first_name, d.dept_name 
FROM employees e 
JOIN department_employees de ON de.emp_no=e.emp_no
JOIN department d ON d.dept_no = de.dept_no;
  1. List first name, last name, and sex of each employee whose first name is Hercules and whose last name begins with the letter B
SELECT e.first_name, e.last_name, e.sex
FROM employees e 
WHERE e.first_name='Hercules' AND e.last_name LIKE 'B%';
  1. List each employee in the Sales department, including their employee number, last name, and first name
SELECT e.emp_no, e.last_name, e.first_name
FROM employees e
JOIN department_employees de ON de.emp_no=e.emp_no
JOIN department d ON d.dept_no = de.dept_no
WHERE d.dept_name='Sales';
  1. List each employee in the Sales and Development departments, including their employee number, last name, first name, and department name
SELECT e.emp_no, e.last_name, e.first_name, d.dept_name
FROM employees e
JOIN department_employees de ON de.emp_no=e.emp_no
JOIN department d ON d.dept_no = de.dept_no
WHERE d.dept_name in ('Sales', 'Development');
  1. List the frequency counts, in descending order, of all the employee last names (that is, how many employees share each last name)
SELECT last_name, COUNT (last_name) AS frequency
FROM employees 
GROUP BY last_name
ORDER BY frequency DESC;