SQL playground

SQL
A dummy HR database for people to practice SQL! Examine tables in this database then use edit the code blocks and hit run to run your query.
Author

Ran Li

Published

August 7, 2023

HR Database Information

erDiagram
  departments ||--o{ employees : has
  jobs ||--o{ employees : has
  employees ||--o{ employees : manages 

  departments {
    department_id INTEGER
    department_name STRING
    location_id INTEGER
  }

  jobs {
    job_id INTEGER
    job_title STRING
    min_salary DOUBLE
    max_salary DOUBLE
  }

  employees {
    employee_id INTEGER
    first_name STRING
    last_name STRING
    email STRING
    phone_number STRING
    hire_date STRING
    job_id INTEGER
    salary DOUBLE
    manager_id INTEGER
    department_id INTEGER
  }


select * from departments ;
select * from jobs  ;
select * from employees ;

SQL Queries

Examples 1, 2, 3 are example SQL queries. Feel free to edit to play around!

This query would return a result set containing the first name, last name, and salary of all employees in the employees table who meet the specified condition.

SELECT first_name, last_name, salary
FROM employees
WHERE salary > 10000;

This query retrieves the first name, last name, and salary of all employees who work in the “IT” department, ordered by salary in descending order.

SELECT e.first_name, e.last_name, e.salary
FROM employees e
JOIN departments d ON e.department_id = d.department_id
WHERE d.department_name = 'IT'
ORDER BY e.salary DESC;

This query retrieves the first name, last name, department name, and total salary of all employees, grouped by department, and includes only those departments with a total salary greater than 20,000.

SELECT d.department_name, SUM(e.salary) AS total_salary
FROM employees e
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.department_name
HAVING SUM(e.salary) > 20000;