Skip to content

This project utilizes SQL and the PostgreSQL database to organize and query employee data.

Notifications You must be signed in to change notification settings

mvongjesda/SQL-Challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL Challenge - Employee Database:

This project utilizes SQL and the PostgreSQL database to organize and query employee data.

Initial data consisted of 6 different csv's of employee data. The data was organized and primary/foreign keys inputted into the web application Quick Database Diagrams to create the ERD below to visualize the table relationships, and to generate the related schema.


After loading in the data and schema into PostgreSQL, the following queries will output the answers to the proposed questions:

--1. List the following details of each employee: employee number, last name, first name, gender, and salary.

SELECT employees.emp_no, employees.last_name, employees.first_name, employees.gender, salaries.salary
FROM employees
JOIN salaries
ON salaries.emp_no = employees.emp_no;

--2. List employees who were hired in 1986.

SELECT emp_no, hire_date FROM employees WHERE hire_date BETWEEN '1986-01-01' AND '1986-12-31';

--3. List the manager of each department with the following information: department number, department name, the manager's employee number, last name, first name, and start and end employment dates.

SELECT departments.dept_no, departments.dept_name, dept_manager.emp_no, employees.last_name, employees.first_name, dept_manager.from_date, dept_manager.to_date FROM dept_manager JOIN departments ON departments.dept_no = dept_manager.dept_no JOIN employees ON employees.emp_no = dept_manager.emp_no;

--4. List the department of each employee with the following information: employee number, last name, first name, and department name.

SELECT dept_emp.emp_no, employees.last_name, employees.first_name, departments.dept_name FROM employees JOIN dept_emp ON dept_emp.emp_no = employees.emp_no JOIN departments ON departments.dept_no = dept_emp.dept_no;

--5. List all employees whose first name is "Hercules" and last names begin with "B."

SELECT first_name, last_name FROM employees WHERE first_name = 'Hercules' AND last_name LIKE 'B%';

--6. List all employees in the Sales department, including their employee number, last name, first name, and department name.

SELECT dept_emp.emp_no, employees.last_name, employees.first_name, departments.dept_name FROM employees JOIN dept_emp ON employees.emp_no = dept_emp.emp_no JOIN departments ON departments.dept_no = dept_emp.dept_no WHERE departments.dept_name = 'Sales'

--7. List all employees in the Sales and Development departments, including their employee number, last name, first name, and department name.

SELECT dept_emp.emp_no, employees.last_name, employees.first_name, departments.dept_name FROM employees JOIN dept_emp ON employees.emp_no = dept_emp.emp_no JOIN departments ON departments.dept_no = dept_emp.dept_no WHERE departments.dept_name = 'Sales' OR departments.dept_name = 'Development';

--8. In descending order, list the frequency count of employee last names, i.e., how many employees share each last name.

SELECT last_name, COUNT(last_name) AS "frequency of names" FROM employees GROUP BY last_name ORDER BY "frequency of names" DESC;

About

This project utilizes SQL and the PostgreSQL database to organize and query employee data.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published