Ejercicios bases de datos
Enviado por Nicolas Garate • 2 de Abril de 2023 • Práctica o problema • 4.046 Palabras (17 Páginas) • 34 Visitas
1.- Escribe un query para extraer los nombres, departamentos y salarios de todos los empleados.
SELECT first_name,
last_name,
department,
salary
FROM employees A
INNER JOIN positions B ON A.position_id = B.position_id
first_name |last_name |department |salary |
-----------|----------|------------|-------|
John |Doe |Marketing |45000 |
Jane |Doe |Sales |40000 |
Bob |Smith |CEO |100000 |
Alice |Jones |HR |70000 |
Mike |Wilson |Engineering |80000 |
Sara |Johnson |Marketing |45000 |
Chris |Williams |Sales |40000 |
Amanda |Brown |Engineering |50000 |
Tom |Davis |HR |40000 |
Emily |Miller |Marketing |45000 |
Andrew |Moore |Sales |40000 |
Emma |Taylor |Engineering |50000 |
Olivia |Thomas |HR |40000 |
Daniel |Jackson |Marketing |45000 |
William |White |Sales |40000 |
Ava |Harris |Engineering |50000 |
James |Martin |HR |40000 |
Abigail |Thompson |Marketing |45000 |
Oliver |Garcia |Sales |40000 |
Elizabeth |Martinez |Engineering |50000 |
2.- Escribe un query para obtener los nombres y títulos (posiciones) de todos los empleados que son managers (es decir, que tienen al
menos un reporte directo a su cargo).
SELECT first_name,
last_name,
title
FROM employees A
INNER JOIN (SELECT DISTINCT manager_id
FROM employees
WHERE manager_id IS NOT NULL) AS MI ON MI.manager_id = A.employee_id
INNER JOIN positions B ON A.position_id = B.position_id
ORDER BY employee_id ASC
first_name |last_name |title |
-----------|----------|--------------------|
John |Doe |Marketing Assistant |
Jane |Doe |Sales Assistant |
Bob |Smith |CEO |
Alice |Jones |HR Manager |
Mike |Wilson |Engineering Manager |
3.- Escribe un query para actualizar el salario de todos los empleados en el departamento 'Sales' a $50,000.
UPDATE positions
SET salary = 50000
WHERE title LIKE 'Sales%'
position_id |title |salary |
------------|----------------------|-------|
1 |Marketing Assistant |45000 |
2 |Marketing Manager |75000 |
3 |Sales Assistant |50000 |
4 |Sales Manager |50000 |
5 |HR Assistant |40000 |
6 |HR Manager |70000 |
7 |Engineering Assistant |50000 |
8 |Engineering Manager |80000 |
9 |CEO |100000 |
4.- Escribe un query para borrar todos los empleados en el departamento 'HR'.
DELETE
FROM employees
WHERE department = 'HR'
employee_id |first_name |last_name |department |manager_id |position_id |
------------|-----------|----------|------------|-----------|------------|
1 |John |Doe |Marketing |3 |1 |
2 |Jane |Doe |Sales |3 |3 |
3 |Bob |Smith |CEO | |9 |
5 |Mike |Wilson |Engineering |4 |8 |
6 |Sara |Johnson |Marketing |1 |1 |
7 |Chris |Williams |Sales |2 |3 |
8 |Amanda |Brown |Engineering |5 |7 |
10 |Emily |Miller |Marketing |1 |1 |
11 |Andrew |Moore |Sales |2 |3 |
12 |Emma |Taylor |Engineering |5 |7 |
14 |Daniel |Jackson |Marketing |1 |1 |
...