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.
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
Create a Table and Import Data
- 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;
- 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';
- 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;
- 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;
- 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%';
- 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';
- 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');
- 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;