{"id":21401388,"url":"https://github.com/kayannr/employee_database","last_synced_at":"2026-05-20T15:03:11.506Z","repository":{"id":136018229,"uuid":"258857191","full_name":"kayannr/Employee_database","owner":"kayannr","description":"(SQL) Data Engineering, Data Modeling, and Data Analysis on Employees of a Corporation using PostgreSQL (pgAdmin)","archived":false,"fork":false,"pushed_at":"2023-09-08T17:57:04.000Z","size":8084,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T03:14:42.262Z","etag":null,"topics":["erdiagram","postgresql","relational-database","sql","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kayannr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-25T19:29:57.000Z","updated_at":"2024-08-27T21:05:08.000Z","dependencies_parsed_at":"2023-11-10T11:59:52.562Z","dependency_job_id":null,"html_url":"https://github.com/kayannr/Employee_database","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kayannr%2FEmployee_database","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kayannr%2FEmployee_database/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kayannr%2FEmployee_database/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kayannr%2FEmployee_database/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kayannr","download_url":"https://codeload.github.com/kayannr/Employee_database/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243893897,"owners_count":20364919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["erdiagram","postgresql","relational-database","sql","sqlalchemy"],"created_at":"2024-11-22T15:27:34.878Z","updated_at":"2026-05-20T15:03:11.403Z","avatar_url":"https://github.com/kayannr.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Employee Database (SQL)\n\n## Background \nThis project involves conducting research on employees of the corporation from the 1980s and 1990s. All that remain of the database of employees from that period are six CSV files. The tables are designed to hold data in the CSVs which is then imported into a SQL database. The following tasks are performed:\n\u003e   * Data Modeling\n\u003e   * Data Engineering\n\u003e   * Data Analysis\n\n## Objectives \n### Data Modeling \nInspect the CSVs and sketch out an ERD of the tables using a tool like [http://www.quickdatabasediagrams.com](http://www.quickdatabasediagrams.com)\n![data](EmployeeSQL/ERD/employees_erd1.png)\n\n### Data Engineering \n* The information are used to create a table schema for each of the six CSV files. Data types, primary keys, foreign keys, and other constraints are specified.\n* Each CSV file are imported into the corresponding SQL table.\n\n```\n- Data Engineering --\n-- Drop Tables if Existing\n--DROP TABLE IF EXISTS departments;\n--DROP TABLE IF EXISTS dept_employees;\n--DROP TABLE IF EXISTS dept_managers;\n--DROP TABLE IF EXISTS employees;\n--DROP TABLE IF EXISTS salaries;\n--DROP TABLE IF EXISTS titles;\n\n-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/\n-- Link to schema: https://app.quickdatabasediagrams.com/#/d/0JOpLb\n-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.\n\n\nCREATE TABLE \"departments\" (\n    \"dept_no\" VARCHAR(4)   NOT NULL,\n    \"dept_name\" VARCHAR(20)   NOT NULL,\n    CONSTRAINT \"pk_departments\" PRIMARY KEY (\n        \"dept_no\"\n     )\n);\n\nCREATE TABLE \"dept_employees\" (\n    \"emp_no\" INTEGER   NOT NULL,\n    \"dept_no\" VARCHAR(4)   NOT NULL\n);\n\nCREATE TABLE \"dept_managers\" (\n    \"dept_no\" VARCHAR(4)   NOT NULL,\n    \"emp_no\" INTEGER   NOT NULL\n);\n\nCREATE TABLE \"employees\" (\n    \"emp_no\" INTEGER   NOT NULL,\n    \"emp_title_id\" VARCHAR(5)   NOT NULL,\n    \"birth_date\" DATE   NOT NULL,\n    \"first_name\" VARCHAR(20)   NOT NULL,\n    \"last_name\" VARCHAR(20)   NOT NULL,\n    \"sex\" VARCHAR(1)   NOT NULL,\n    \"hire_date\" DATE   NOT NULL,\n    CONSTRAINT \"pk_employees\" PRIMARY KEY (\n        \"emp_no\"\n     )\n);\n\nCREATE TABLE \"salaries\" (\n    \"emp_no\" INTEGER   NOT NULL,\n    \"salary\" INTEGER   NOT NULL\n);\n\nCREATE TABLE \"titles\" (\n    \"title_id\" VARCHAR(5)   NOT NULL,\n    \"title\" VARCHAR(20)   NOT NULL,\n    CONSTRAINT \"pk_titles\" PRIMARY KEY (\n        \"title_id\"\n     )\n);\n\nALTER TABLE \"dept_employees\" ADD CONSTRAINT \"fk_dept_employees_emp_no\" FOREIGN KEY(\"emp_no\")\nREFERENCES \"employees\" (\"emp_no\");\n\nALTER TABLE \"dept_employees\" ADD CONSTRAINT \"fk_dept_employees_dept_no\" FOREIGN KEY(\"dept_no\")\nREFERENCES \"departments\" (\"dept_no\");\n\nALTER TABLE \"dept_managers\" ADD CONSTRAINT \"fk_dept_managers_dept_no\" FOREIGN KEY(\"dept_no\")\nREFERENCES \"departments\" (\"dept_no\");\n\nALTER TABLE \"dept_managers\" ADD CONSTRAINT \"fk_dept_managers_emp_no\" FOREIGN KEY(\"emp_no\")\nREFERENCES \"employees\" (\"emp_no\");\n\nALTER TABLE \"employees\" ADD CONSTRAINT \"fk_employees_emp_title_id\" FOREIGN KEY(\"emp_title_id\")\nREFERENCES \"titles\" (\"title_id\");\n\nALTER TABLE \"salaries\" ADD CONSTRAINT \"fk_salaries_emp_no\" FOREIGN KEY(\"emp_no\")\nREFERENCES \"employees\" (\"emp_no\");\n\n\n-- Query * FROM Each Table To Confirm Data Is Correct\nSELECT * FROM \"titles\"; \nSELECT * FROM \"employees\"; \nSELECT * FROM \"salaries\"; \nSELECT * FROM \"departments\"; \nSELECT * FROM \"dept_employees\"; \nSELECT * FROM \"dept_managers\"; \n```\n\n### Data Analysis\n\n1. List the following details of each employee: employee number, last name, first name, sex, and salary.\n```\nSELECT employees.emp_no, employees.last_name,employees.first_name,employees.sex, salaries.salary\n\tFROM employees\n\tJOIN salaries ON employees.emp_no = salaries.emp_no;\n```\n\n2. List first name, last name, and hire date for employees who were hired in 1986.\n```\nSELECT first_name, last_name, hire_date\n\tFROM employees\n\tWHERE extract(year from hire_date) = 1986;\n```\n\n3. List the manager of each department with the following information: department number, department name, the manager's employee number, last name, first name.\n```\nSELECT departments.dept_no, departments.dept_name,dept_managers.emp_no, \n\t\temployees.last_name, employees.first_name \n\tFROM departments \n\tINNER JOIN dept_managers ON departments.dept_no=dept_managers.dept_no\n\tINNER JOIN employees ON dept_managers.emp_no=employees.emp_no; \n```\n\n4. List the department of each employee with the following information: employee number, last name, first name, and department name.\n```\nSELECT employees.emp_no, employees.last_name, employees.first_name, departments.dept_name\n\tFROM employees \n\tINNER JOIN dept_employees ON employees.emp_no=dept_employees.emp_no\n\tINNER JOIN departments ON departments.dept_no=dept_employees.dept_no; \n```\n\n5. List first name, last name, and sex for employees whose first name is \"Hercules\" and last names begin with \"B.\"\n```\nSELECT first_name, last_name, sex\n\tFROM employees \n\tWHERE first_name='Hercules' AND last_name LIKE 'B%'; \n```\n\n6. List all employees in the Sales department, including their employee number, last name, first name, and department name.\n```\nSELECT employees.emp_no, employees.first_name, employees.last_name, departments.dept_name\n\tFROM employees\n\tINNER JOIN dept_employees ON dept_employees.emp_no=employees.emp_no\n\tINNER JOIN departments ON departments.dept_no=dept_employees.dept_no\n\tWHERE dept_name = 'Sales'; \n```\n\n7. List all employees in the Sales and Development departments, including their employee number, last name, first name, and department name.\n```\nSELECT employees.emp_no, employees.last_name, employees.first_name, departments.dept_name\n\tFROM employees\n\tINNER JOIN dept_employees ON dept_employees.emp_no=employees.emp_no\n\tINNER JOIN departments ON departments.dept_no=dept_employees.dept_no\n\tWHERE dept_name = 'Sales' OR dept_name ='Development'; \n```\n\n8. In descending order, list the frequency count of employee last names, i.e., how many employees share each last name.\n```\nSELECT last_name, COUNT(first_name) AS \"last_name_count\"\n\tFROM employees\n\tGROUP BY last_name\n\tORDER BY \"last_name_count\" DESC;\n```\n\n\n## Employee Salary\n![data2](EmployeeSQL/Analysis-python-sqlalchemy/SalariesVsTitles.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkayannr%2Femployee_database","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkayannr%2Femployee_database","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkayannr%2Femployee_database/lists"}