Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions delete.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--Delete all employees with a salary greater than 20,000
DELETE FROM salaries WHERE salary >20000;

--Remove the department that has more employees
DELETE FROM dept_emp WHERE COUNT(emp_no)
102 changes: 102 additions & 0 deletions insertData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
-- Insert Data

INSERT INTO employees (emp_no, birth_date, First_name, last_name, gender, hire_date)
values
('1', '1998-12-15', 'Mike', 'Navarro', 'M', '2018-03-20'),
('2', '1985-11-05', 'Mike', 'Smith', 'M', '2021-04-19'),
('3', '1999-05-12', 'Mike', 'Herrera', 'M', '2020-05-18'),
('4', '1989-01-08', 'Carolina', 'Herrera', 'F', '2018-01-14'),
('5', '1998-12-15', 'Collete', 'Delacroix', 'F', '2018-03-20'),
('6', '1995-06-10', 'Petronila', 'López', 'M', '2018-03-20'),
('7', '1983-09-17', 'Pierre', 'Nodoiuna', 'M', '2019-04-19'),
('8', '1998-02-14', 'Pedro', 'Bello', 'M', '2021-06-20'),
('9', '1995-09-23', 'Penélope', 'Glamour', 'F', '2018-01-14'),
('10', '1995-06-10', 'Sis', 'Macana', 'F', '2019-04-19'),
('11', '1995-06-10', 'Jamie', 'Locobich', 'M', '2018-01-14'),
('12', '1987-07-18', 'Hans', 'Fritz', 'M', '2018-01-14'),
('13', '1993-08-06', 'Luke', 'Granero', 'M', '2021-04-19'),
('14', '1987-07-18', 'Patan', 'Muttley', 'M', '2018-01-14'),
('15', '1991-10-25', 'Blast', 'Meekly', 'F', '2021-04-19');

INSERT INTO salaries ( emp_no, salary, from_date, to_date) values
('1', '8000', '2018-03-20', '2021-01-01'),
('1', '25000', '2021-01-01', UTC_DATE()),
('2', '7000', '2021-04-19', UTC_DATE()),
('3', '8500', '2020-05-18', UTC_DATE()),
('4', '25000', '2018-01-14', '2020-01-14'),
('4', '40000', '2020-01-14', UTC_DATE()),
('5', '12000', '2018-03-20', '2019-03-20'),
('5', '20000', '2019-03-20', '2020-03-20'),
('5', '32000', '2020-03-20', UTC_DATE()),
('6', '5000', '2018-03-20', '2019-03-20'),
('6', '16000', '2019-03-20', UTC_DATE()),
('7', '30000', '2019-04-19', UTC_DATE()),
('8', '10000', '2021-06-20', UTC_DATE()),
('9', '6000', '2018-01-14', '2019-01-14'),
('9', '10000', '2019-01-14', '2020-01-14'),
('10', '30000', '2019-04-19', UTC_DATE()),
('11', '30000', '2018-01-14', UTC_DATE()),
('12', '20000', '2018-01-14', UTC_DATE()),
('13', '10000', '2021-04-19', UTC_DATE()),
('14', '9000', '2018-01-14', UTC_DATE()),
('15', '6000', '2021-04-19', UTC_DATE());

INSERT INTO departments (dept_no, dept_name) values
('1', 'Finance '),
('2', ' Human Resources'),
('3', 'Marketing'),
('4', 'Sales'),
('5', 'General Management'),
('6', 'Logistics');

INSERT INTO dept_emp (emp_no, dept_no, from_date, to_date) values
('1', '1', '2018-03-20', UTC_DATE()),
('1', '4', '2021-01-01', UTC_DATE()),
('2', '3', '2021-04-19', UTC_DATE()),
('3','2','2020-05-18', UTC_DATE()),
('3','3', '2020-05-18', UTC_DATE()),
('4', '1', '2018-01-14', UTC_DATE()),
('4', '5', '2020-01-14', UTC_DATE()),
('5', '4', '2018-03-20','2021-06-20'),
('5', '3', '2019-03-20', UTC_DATE()),
('5', '5', '2020-03-20', UTC_DATE()),
('6','3','2019-03-20', UTC_DATE()),
('7', '6', '2019-04-19', UTC_DATE()),
('7', '1', '2019-04-19', UTC_DATE()),
('8','5', '2022-01-17', UTC_DATE()),
('8','4', '2021-06-20', UTC_DATE()),
('9','1', '2018-01-14','2020-01-14'),
('9','4', '2019-01-14','2020-01-14'),
('10', '5', '2019-04-19', UTC_DATE()),
('10', '2', '2019-04-19', UTC_DATE()),
('11', '1', '2018-01-14', UTC_DATE()),
('12', '5', '2018-01-14', UTC_DATE()),
('12', '6', '2018-01-14', UTC_DATE()),
('13', '4', '2021-04-19', UTC_DATE()),
('13', '1', '2021-04-19', UTC_DATE()),
('14', '6','2018-01-14' ,UTC_DATE()),
('15','4', '2021-04-19', UTC_DATE());

INSERT INTO dept_manager (emp_no, dept_no, from_date, to_date) values
('4','1', '2020-01-14', UTC_DATE()),
('5','3', '2020-03-20', UTC_DATE()),
('8','4', '2022-01-17', UTC_DATE()),
('10','2', '2019-04-19', UTC_DATE()),
('12','6', '2018-01-14', UTC_DATE());

INSERT INTO titles (emp_no, title, from_date, to_date ) values
('1','Finance', '2018-09-15', '2020-06-22'),
('2',' Marketing and Commerce', '2018-09-15', '2020-06-22'),
('3', 'Advertising and public relations', '2008-09-15', '2010-06-20'),
('4', 'Advertising and public relations', '2008-09-15', '2010-06-20'),
('5', 'Trades and sales', '2018-09-15', '2020-06-22'),
('6', ' Marketing and Commerce', '2012-09-12', '2015-06-20'),
('7', 'Advertising and public relations', '2008-09-15', '2010-06-20'),
('8', 'Trades and sales', '2018-09-15', '2020-06-22'),
('9', ' Marketing and Commerce', '2012-09-12', '2015-06-20'),
('10', ' Marketing and Commerce', '2012-09-12', '2015-06-20'),
('11', ' Marketing and Commerce', '2012-09-12', '2015-06-20'),
('12', 'Industrial logistics', '2012-09-12', '2015-06-20'),
('13', 'Trades and sales', '2018-09-15', '2020-06-22'),
('14', 'Industrial logistics', '2012-09-12', '2015-06-20'),
('15','Commerce', '2010-09-08', '2013-06-22') ;
54 changes: 54 additions & 0 deletions select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

--Select all employees with a salary greater than 20,000
SELECT employees.first_name, employees.last_name, salaries.salary
FROM employees
INNER JOIN salaries
ON employees.emp_no = salaries.emp_no
WHERE salaries.salary>20000;


--Select all employees with a salary below 10,000
SELECT employees.first_name, employees.last_name, salaries.salary
FROM employees
INNER JOIN salaries
ON employees.emp_no = salaries.emp_no
WHERE salaries.salary<10000;

--Select all employees who have a salary between 14000 and 50,000
SELECT employees.first_name, employees.last_name, salaries.salary
FROM employees
INNER JOIN salaries
ON employees.emp_no = salaries.emp_no
WHERE salaries.salary BETWEEN 14000 AND 50000;

--Select the total number of employees
SELECT COUNT(emp_no)
FROM employees;

--Select the total number of employees who have worked in more than one department
SELECT emp_no, COUNT(emp_no) FROM dept_emp GROUP BY emp_no HAVING COUNT(emp_no) >1;

--Select the titles of the year 2019
SELECT * FROM titles WHERE to_date LIKE '%2020%';

--Select only the name of the employees in capital letters
Select * From employees Where first_name = UPPER(first_name);

--Select the name, surname and name of the current department of each employee
SELECT employees.first_name, employees.last_name, departments.dept_name
FROM employees
LEFT JOIN dept_emp ON dept_emp.emp_no = employees.emp_no
LEFT JOIN departments ON dept_emp.dept_no = departments.dept_no
WHERE dept_emp.to_date = UTC_DATE() ;

--Select the name, surname and number of times the employee has worked as a manager
SELECT employees.first_name, employees.last_name, departments.dept_name
FROM employees
LEFT JOIN dept_manager ON dept_manager.emp_no = employees.emp_no
LEFT JOIN departments ON dept_manager.dept_no = departments.dept_no
WHERE dept_manager.to_date = UTC_DATE();

--Select the name of employees without any being repeated
SELECT MIN(emp_no), first_name
FROM employees
GROUP BY first_name;
25 changes: 25 additions & 0 deletions updateData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Update Employee name

UPDATE employees
SET first_name = 'Penelope'
WHERE employees.emp_no = 9;

--Update Department name
UPDATE departments
SET dept_name = 'Dep. Finance '
WHERE departments.dept_no = '1';
UPDATE departments
SET dept_name = 'Dep. Human Resources'
WHERE departments.dept_no = '2';
UPDATE departments
SET dept_name = 'Dep. Marketing'
WHERE departments.dept_no = '3';
UPDATE departments
SET dept_name = 'Dep. Sales'
WHERE departments.dept_no = '4';
UPDATE departments
SET dept_name = 'Dep. General Management'
WHERE departments.dept_no = '5';
UPDATE departments
SET dept_name = 'Dep. Logistics'
HERE departments.dept_no = '6';