{"id":21293390,"url":"https://github.com/ejw-data/postgres-sql-employee","last_synced_at":"2026-04-14T06:33:55.166Z","repository":{"id":39734172,"uuid":"215954964","full_name":"ejw-data/postgres-sql-employee","owner":"ejw-data","description":"PostgreSQL DB development then analysis within Jupyter notebook using SQLAlchemy, Pandas, and Matplotlib","archived":false,"fork":false,"pushed_at":"2022-11-03T02:39:31.000Z","size":15442,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-28T17:07:35.360Z","etag":null,"topics":["postgresql","python","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/ejw-data.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}},"created_at":"2019-10-18T06:22:37.000Z","updated_at":"2022-11-25T14:47:33.000Z","dependencies_parsed_at":"2023-01-21T11:46:06.783Z","dependency_job_id":null,"html_url":"https://github.com/ejw-data/postgres-sql-employee","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ejw-data/postgres-sql-employee","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejw-data%2Fpostgres-sql-employee","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejw-data%2Fpostgres-sql-employee/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejw-data%2Fpostgres-sql-employee/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejw-data%2Fpostgres-sql-employee/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ejw-data","download_url":"https://codeload.github.com/ejw-data/postgres-sql-employee/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejw-data%2Fpostgres-sql-employee/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31785677,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T02:24:21.117Z","status":"ssl_error","status_checked_at":"2026-04-14T02:24:20.627Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["postgresql","python","sqlalchemy"],"created_at":"2024-11-21T13:54:34.064Z","updated_at":"2026-04-14T06:33:55.150Z","avatar_url":"https://github.com/ejw-data.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# postgres-sql-employee\n\nAuthor:  Erin James Wills, ejw.data@gmail.com  \n\n![Employee Database](./images/employee-postgres-db.png)\n\u003ccite\u003ePhoto by [Tobias Fischer](https://unsplash.com/@tofi?utm_source=unsplash\u0026utm_medium=referral\u0026utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/database?utm_source=unsplash\u0026utm_medium=referral\u0026utm_content=creditCopyText)\u003c/cite\u003e \n\n\u003cbr\u003e\n\n## Overview\n\u003chr\u003e  \n\nThe purpose of this repo is to create a database of employee information.  The records in the database are fictitious so no personal information is being exposed.  The database is made up of 6 tables with primary keys and some foreign keys.  The structure of the database is display below but the key tables include an employee information table, a salary table, a department managers, and a department employees table.  Essentially, information about each employee is accessible including if the person works in one or more departments, if they are a manager, and what their base salary is.    \n\nWithin this repo is a schema sql file for generating the table structure.  In addition, for each table there is a csv file of data. The accompanying Jupyter Notebook includes SQLAlchemy code for performing queries on the database and showing how that data can be used in dataframes and matplotlib charts.  A separate set of queries can also be found in a SQL script that can be run directly from pgAdmin.   Note:  The QuickDatabaseDiagrams website was used to generate the table structure.  The script for that web-based toolis also located in the repo.    \n\n\u003cbr\u003e\n\n## Technologies  \n*  Python\n*  PostgreSQL/SQL\n*  SQLAlchemy\n*  [QuickDatabaseDiagrams](https://www.quickdatabasediagrams.com/)\n\n\u003cbr\u003e\n\n## Data Source  \nDataset generated by Trilogy Education Services. Origins beyond this is unknown. \n\n\u003cbr\u003e\n\n## Setup and Installation  \n1. Setup Postgres Database\n    *  Create database in pgAdmin called `employee_db`\n    *  Open a Query Tool and paste/open the contents of `database_setup/schema_query.sql`\n    *  Run this entire script.  \n    *  Next load the data into the database.  \n        *  First, right click on schema and select Import/Export Data\n        *  Select Import button\n        *  Select the file location `data/titles.csv`\n        *  Select the 'has headers' button\n        *  Select the delimiter to be a 'comma' \n        *  Select Okay.  The data should import quickly.  \n    *  Repeat the process above for the following files in this specific order:\n        *  `departments.csv`\n        *  `employees.csv`\n        *  `salaries.csv`\n        *  `dept_emp.csv`\n        *  `dept_manager.csv`\n    *  Test that the database loaded correctly by making a couple queries:  \n        *  `Select * from salaries;`\n        *  etc....\n    *  Next, test out specific queries found in the `database_setup/query_database.sql`\n1.  Next Setup your Environment with:  \n    *  Python 3.6+  \n    *  pandas  \n    *  numpy\n    *  sqlalchemy\n    *  psycopg2\n1. Activate your environment\n1. Clone the repo to your local machine\n1. Start Jupyter Notebook within the environment from the repo folder\n1. Run `analysis/data_analysis.ipynb` \n\n\u003cbr\u003e\n\n## Analysis  \n*  For example SQL queries, run `database_setup/query_database.sql`.\n*  For example ORM SQLAlchemy queries and pandas plots, run `data_analysis.ipynb`  \n*  Demonstrated in the notebook is one method of using SQLAlchemy.  I prefer the ORM method over the SQLAlchemy Table method.  \n*  Checkout my repo called `sqlalchemy-flask-api-weather` for my preferred style.  \n\n\u003cbr\u003e\n\n\u003cfigure\u003e\n\n![PostgreSQL DB Development and Analsysis](./images/QuickDBD-screen_capture.png)\n\u003cfigcaption\u003eFig.1 - Screenshot of QuickDatabaseDiagrams.com Schema Creater\u003c/figcaption\u003e\n\u003c/figure\u003e\n\u003cbr\u003e\n\n## Sample Queries from pgAdmin \n\n1. List the following details of each employee: employee number, last name, first name, gender, and salary.  \n   \u003eSelect employees.emp_no, employees.last_name, employees.first_name, employees.gender, salaries.salary  \nFrom employees, salaries\nWhere employees.emp_no = salaries.emp_no\n\n2. List employees who were hired in 1986.  \n   \u003eSelect employees.emp_no, employees.last_name, employees.first_name, employees.hire_date\nFrom employees\nWhere Extract(Year FROM hire_date) = 1986\n\n3. List the manager of each department with the following information: department number, department name, \n-- the manager's employee number, last name, first name, and start and end employment dates.  \n   \u003eSelect departments.dept_no, departments.dept_name, dept_manager.emp_no, employees.last_name, employees.first_name, dept_manager.from_date, dept_manager.to_date  \n   \u003eFrom departments  \n    INNER Join dept_manager On departments.dept_no = dept_manager.dept_no  \n    Inner Join employees On employees.emp_no = dept_manager.emp_no  \n\n4. List the department of each employee with the following information: employee number, last name, \n-- first name, and department name.   \n   \u003eSelect employees.emp_no, employees.last_name, employees.first_name, departments.dept_name  \nFrom employees  \nInner Join dept_emp on dept_emp.emp_no = employees.emp_no  \nInner Join departments on dept_emp.dept_no = departments.dept_no  \n\n5. List all employees whose first name is \"Hercules\" and last names begin with \"B.\"  \n   \u003eSelect employees.first_name, employees.last_name\nFrom employees   \nWhere employees.first_name = 'Hercules' AND   \nLEFT(employees.last_name, 1) = 'B'  \n\n6. List all employees in the Sales department, including their employee number, last name, first name, and department name.\n   \u003eSelect employees.emp_no, employees.last_name, employees.first_name, departments.dept_name  \nFrom employees  \nInner Join dept_emp on dept_emp.emp_no = employees.emp_no   \nInner Join departments on dept_emp.dept_no = departments.dept_no   \nWhere dept_emp.dept_no = 'd007'   \n\n7. List all employees in the Sales and Development departments, including their employee number, last name, first name, and department name.   \n   \u003eSelect employees.emp_no, employees.last_name, employees.first_name, departments.dept_name\nFrom employees  \nInner Join dept_emp on dept_emp.emp_no = employees.emp_no  \nInner Join departments on dept_emp.dept_no = departments.dept_no  \nWhere dept_emp.dept_no = 'd007' OR dept_emp.dept_no = 'd005'  \n\n8. In descending order, list the frequency count of employee last names, i.e., how many employees share each last name.\n   \u003eSelect employees.last_name, count(employees.last_name)  \nFrom employees  \nGroup By employees.last_name  \nOrder By count(employees.last_name) DESC  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fejw-data%2Fpostgres-sql-employee","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fejw-data%2Fpostgres-sql-employee","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fejw-data%2Fpostgres-sql-employee/lists"}