Tarea 1
Luis Antonio Sánchez Montalvo 316070304
-- Problema 1
CREATE database human_resources;
use human_resources;
DROP TABLE IF EXISTS employees;
CREATE TABLE employees (
emp_id INT NOT NULL PRIMARY KEY,
emp_name VARCHAR(15) NOT NULL,
job_name VARCHAR(10),
manager_id INT,
hire_date DATE,
salary DECIMAL(10,2),
commission DECIMAL(7,2),
dep_id INT);
INSERT INTO employees (emp_id, emp_name, job_name, manager_id, hire_date, salary,
commission, dep_id)
VALUES (68319, 'KAYLING', 'PRESIDENT', NULL, '1991-11-18', 6000.00, NULL, 1001),
(66928, 'BLAZE', 'MANAGER', 68319, '1991-05-01', 2750.00, NULL, 3001),
(67832, 'CLARE', 'MANAGER', 68319, '1991-06-09', 2550.00, NULL, 1001),
(65646, 'JONAS', 'MANAGER', 68319, '1991-04-02', 2957.00, NULL, 2001),
(67858, 'SCARLET', 'ANALYST', 65646, '1997-04-19', 3100.00, NULL, 2001),
(69062, 'FRANK', 'ANALYST', 65646, '1991-12-03', 3100.00, NULL, 2001),
(63679, 'SANDRINE', 'CLERK', 69062, '1990-12-18', 900.00, NULL, 2001),
(64989, 'ADELYN', 'SALESMAN', 66928, '1991-02-20', 1700.00, 400.00, 3001),
(65271, 'WADE', 'SALESMAN', 66928, '1991-02-22', 1350.00, 600.00, 3001),
(66564, 'MADDEN', 'SALESMAN', 66928, '1991-09-28', 1350.00, 1500.00, 3001),
(68454, 'TUCKER', 'SALESMAN', 66928, '1991-09-08', 1600.00, 0.00, 3001),
(68736, 'ADNRES', 'CLERK', 67858, '1997-05-23', 1200.00, NULL, 2001),
(69000, 'JULIUS', 'CLERK', 66928, '1991-12-03', 1050.00, NULL, 3001),
(69324, 'MARKER', 'CLERK', 67832, '1992-01-23', 1400.00, NULL, 1001);
SELECT * from employees;
-- Problema no 2
SELECT salary from employees;
-- Probelma no 3
SELECT job_name from employees;
-- Probelma no 4
SELECT emp_name, CONCAT('$', ROUND(salary * 1.15)) AS new_salary FROM employees;
-- Problema no 5
SELECT CONCAT(emp_name, ' ', job_name) AS 'Employee & Job' FROM employees;
-- Problema no 6
SELECT CONCAT(emp_name, '(', job_name, ')') AS Employee FROM employees;
-- Problema 7
SELECT emp_id, emp_name, salary, DATE_FORMAT(hire_date, '%M %d, %Y') AS
hire_date_formatted FROM employees;
-- Problema 8
SELECT LENGTH(REPLACE(emp_name, ' ', '')) as 'length' FROM employees;
-- Problema 9
SELECT emp_id, salary, commission From employees ;
-- Problema 10
SELECT DISTINCT dep_id, job_name FROM employees;
-- Problema 11
SELECT * FROM employees
WHERE dep_id NOT IN (2001);
-- Problema 12
SELECT * from employees
where hire_date < '1991-01-01';
-- Problema 13
SELECT AVG(salary) AS avg_salary FROM employees WHERE job_name = 'ANALYST';
-- Problema 14
SELECT * from employees WHERE emp_name = 'BLAZE';
-- Problema 15
SELECT * from employees where commission > salary ;
-- Problema 16
SELECT * from employees where ROUND(salary * 1.25) > 3000 ;
-- Problema 17
SELECT emp_name from employees WHERE LENGTH(emp_name)=6;
-- Problema 18
SELECT * from employees WHERE MONTH(hire_date) = '01';
-- Problema 19
SELECT CONCAT(e.emp_name, ' works for ', (SELECT emp_name FROM employees WHERE
emp_id = e.manager_id)) AS emp_manager
FROM employees e;
-- Problema 20
SELECT * FROM employees WHERE job_name = 'CLERK';
-- Problema 21
SELECT * FROM employees WHERE DATEDIFF(NOW(), hire_date) > 27*365;
(hay más rows)
-- Problema 22
SELECT * FROM employees WHERE salary < 3500;
(hay más rows)
-- Problema 23
SELECT emp_name, job_name, salary From employees WHERE job_name = 'ANALYST';
-- PROBLEMA 24
SELECT * from employees where YEAR (hire_date) = YEAR ('1991-01-01');
(hay más rows)
-- Problema 25
SELECT emp_id , emp_name , hire_date , salary from employees
WHERE hire_date < '1991-04-01';
-- Problema 26
SELECT emp_name, job_name FROM employees WHERE manager_id IS NULL;
-- Problema 27
SELECT * from employees WHERE hire_date = '1991-05-01';
-- Problema 28
SELECT e.emp_id, e.emp_name, e.salary,
CONCAT(
TIMESTAMPDIFF(YEAR, e.hire_date, NOW()), ' years ',
MOD(TIMESTAMPDIFF(MONTH, e.hire_date, NOW()), 12), ' months ',
MOD(TIMESTAMPDIFF(DAY, e.hire_date, NOW()), 30), ' days'
) AS experience
FROM employees e
WHERE e.manager_id = 68319;
-- Problema 29
SELECT e.emp_id, e.emp_name, e.salary,
CONCAT(
TIMESTAMPDIFF(YEAR, e.hire_date, NOW()), ' years ',
MOD(TIMESTAMPDIFF(MONTH, e.hire_date, NOW()), 12), ' months ',
MOD(TIMESTAMPDIFF(DAY, e.hire_date, NOW()), 30), ' days'
) AS experience
FROM employees e
WHERE e.salary/30 > 100;
-- Problema 30
SELECT e.emp_name from employees e
WHERE TIMESTAMPDIFF(YEAR, e.hire_date, '1999-12-31') < 8;
-- Problema 31
SELECT * FROM employees WHERE MOD(salary, 2) = 1;
-- Problema 32
SELECT * FROM employees WHERE salary BETWEEN 100 AND 999;
-- Problema 33
SELECT * from employees WHERE MONTH(hire_date) = 4;
-- Problema 34
SELECT * FROM employees WHERE DAY(hire_date) < 19;
(hay más rows)
-- Problema 35
SELECT * FROM employees WHERE job_name = 'SALESMAN';
-- Problema 36
SELECT * FROM employees WHERE (dep_id = 3001 OR dep_id = 1001)
AND YEAR(hire_date) = 1991;
-- Problema 37
SELECT * FROM employees WHERE (dep_id = 2001 OR dep_id = 1001);
(hay más rows)
-- Problema 38
SELECT * FROM employees WHERE job_name = 'CLERK' AND dep_id = 2001;
-- Problema 39
SELECT emp_id, emp_name, salary, job_name FROM employees
WHERE commission <= salary AND (salary + (commission * 12)) < 34000
AND job_name = 'SALESMAN' AND dep_id = 3001;
-- Problema 40
SELECT * FROM employees WHERE (job_name = 'CLERK' OR job_name= 'MANAGER');
-- Problema 41
SELECT * FROM employees WHERE NOT MONTH(hire_date) = 2;
(hay más rows)
-- Problema 42
SELECT * FROM employees WHERE YEAR(hire_date) = 1991;
(hay más rows)
-- Problema 43
SELECT * FROM employees WHERE YEAR(hire_date) = 1991 AND MONTH(hire_date) = 6;
-- Problema 44
SELECT * FROM employees WHERE salary*12 BETWEEN 24000 AND 50000;
-- Problema 45
SELECT * FROM employees WHERE hire_date IN ('1991-05-01', '1991-02-20', '1991-12-03');
-- Problema 46
SELECT * FROM employees WHERE manager_id IN (63679, 68319, 66564, 69000);
-- Problema 47
SELECT * FROM employees WHERE hire_date >= '1991-07-01' AND hire_date <= '1991-12-
31';
-- Problema 48
SELECT * FROM employees WHERE hire_date >= '1990-01-01' AND hire_date < '2000-01-01';
-- Problema 49
SELECT * FROM employee WHERE job_name = 'MANAGER' AND dep_id IN (1001, 2001);
-- Problema 50
SELECT * FROM employees WHERE MONTH (hire_date)= 2 AND salary BETWEEN 1001
AND 2000;
-- Problema 51
SELECT * FROM employees WHERE hire_date < '1991-01-01' OR hire_date > '1991-12-31';