Employees sample database
An org chart: people, departments, salaries and who reports to whom.
2 tables · 42 rows · 12 KB
Tables
departments 5 rows
- id integer PK
- name text
- location text
| id | name | location |
|---|---|---|
| 1 | Engineering | San Francisco |
| 2 | Sales | New York |
| 3 | Marketing | Los Angeles |
employees 37 rows
- id integer PK
- first_name text
- last_name text
- email text
- department_id integer → departments
- salary integer
- hire_date text
- manager_id integer → employees
- title text
| id | first_name | last_name | department_id | salary | hire_date | manager_id | title | |
|---|---|---|---|---|---|---|---|---|
| 1 | Alice | Chen | [email protected] | 1 | 250000 | 2015-01-15 | NULL | CEO |
| 2 | Robert | Martinez | [email protected] | 2 | 180000 | 2016-03-20 | NULL | CEO |
| 3 | Sarah | Johnson | [email protected] | 1 | 150000 | 2017-06-10 | 1 | VP Engineering |
How the tables connect
- employees.manager_idemployees.id
- employees.department_iddepartments.id
Try a query
Use it on your computer
The SQLite file opens with the sqlite3 command-line tool or any SQLite app:
sqlite3 employees.sqlite
.tables
For MySQL, PostgreSQL or SQL Server, run the SQL script instead. It is plain CREATE TABLE and INSERT statements
written for SQLite, so another database may need a small change.
29 practice questions on this database
- Easy Second Highest Salary Find the Runner-Up Salary Free
- Easy Departments With More Than 5 Employees Large Department Report Free
- Easy Employees Hired in the Last 90 Days New Hire Onboarding List Free
- Easy Employees Without a Manager Employees Without Managers Free
- Easy Salaries Over $100,000 Six-Figure Earners Free
- Easy Earliest and Latest Date Hiring Date Range Free
- Easy Replace NULL With COALESCE Handle Missing Data with COALESCE Free
- Easy Salary Bands With CASE WHEN Classify Employees by Salary Tier Free
- Easy Conditional Count With SUM and CASE Conditional Counting with SUM+CASE Free
- Easy UPDATE Rows With a Condition Engineering Gets a Raise Free
- Easy WHERE vs HAVING Filter Rows and Groups With WHERE and HAVING Free
- Medium Top 3 Salaries per Department Identify Top 3 Earners per Department Premium
- Medium Employee and Manager Self Join Employee Reporting Structure Premium
- Medium 90th Percentile Salary Calculate 90th Percentile Salary Free
- Medium Employees Hired on the Same Day Find Employees Hired on Same Day Premium
- Medium Salary vs Department Average Compare Employee Salary to Department Average Premium
- Medium UPDATE With CASE Tiered Annual Bonus Premium
- Medium Reassign Rows With UPDATE The Manager Moved On Premium
- Medium Nth Highest Salary Find the Nth Highest Salary Free
- Medium Highest Salary in Each Department Find the Highest Salary in Each Department Free
- Medium Employees Who Are Managers Find Employees Who Manage Someone Free
- Medium Employees With the Same Salary Find Employees Who Share a Salary Free
- Medium Second Highest Salary per Department Second Highest Salary in Each Department Free
- Medium Department With the Most Employees Departments With the Most Recent Hires Free
- Hard Median Without a MEDIAN Function Department Salary Median (No MEDIAN Function) Premium
- Hard Org Chart Hierarchy With a Recursive CTE Full Organizational Hierarchy Depth Premium
- Hard Cumulative Distribution Cumulative Salary Distribution Premium
- Hard Fibonacci With a Recursive CTE Generate Fibonacci Sequence with SQL Premium
- Hard SAVEPOINT and ROLLBACK TO The Reversible Experiment Premium
Practice on your iPhone
Query Dojo for iPhone has 85 interview questions, timed mock interviews and a tile builder, so you can write queries without a keyboard.