Sunteți pe pagina 1din 3

Miguel Angel Marin Encina

Fundamentos de Base de Datos


10-11hrs
A)

Subconsultas donde se involucran 2 o ms tablas (por consulta).

1)

Reportar el ltimo perodo laboral del empleado Neena kochhar.

SQL>
2
3
4

SELECT last_name||' '||first_name "Nombre", end_date "Ultimo Periodo"


FROM employees,job_history
WHERE job_history.employee_id = employees.employee_id
AND first_name = 'Neena' AND last_name = 'Kochhar';

Nombre
---------------------------------------------Kochhar Neena
Kochhar Neena
2)
s).
SQL>
2
3
4
5

Ultimo P
-------27/10/93
15/03/97

Reportar en qu pas se encuentra localizado el departamento de ventas (Sale


SELECT department_name "Departamento" ,city "Ciudad" ,country_name "Pais"
FROM locations,countries,departments
WHERE locations.country_id=countries.country_id
AND departments.location_id = locations.location_id
AND department_name = 'Sales';

Departamento
Ciudad
------------------------------ -----------------------------Pais
---------------------------------------Sales
Oxford
United Kingdom
3)
SQL>
2
3
4
5

Reportar los perodos laborales que ha tenido el empleado Jonathon Taylor.


SELECT last_name||' '||first_name Nombre,
start_date Inicio, end_date Fin
FROM employees, job_history
WHERE employees.employee_id = job_history.employee_id
AND first_name='Jonathon' AND last_name = 'Taylor';

NOMBRE
---------------------------------------------Taylor Jonathon
Taylor Jonathon

INICIO
-------24/03/98
01/01/99

FIN
-------31/12/98
31/12/99

4)
Reportar los nombres de los empleados que se encuentran trabajando en lo
s departamentos ubicados en Seattle.
SQL>
2
3
4
5
6

SELECT last_name||' '||first_name Nombre,


department_name Departamento, city Ciudad
FROM employees, departments, locations
WHERE employees.department_id = departments.department_id
AND departments.location_id = locations.location_id
AND city = 'Seattle';

NOMBRE
DEPARTAMENTO
---------------------------------------------- -----------------------------CIUDAD

-----------------------------Whalen Jennifer
Seattle

Administration

Raphaely Den
Seattle

Purchasing

Khoo Alexander
Seattle

Purchasing

NOMBRE
DEPARTAMENTO
---------------------------------------------- -----------------------------CIUDAD
-----------------------------Baida Shelli
Purchasing
Seattle
Tobias Sigal
Seattle

Purchasing

Himuro Guy
Seattle

Purchasing

NOMBRE
DEPARTAMENTO
---------------------------------------------- -----------------------------CIUDAD
-----------------------------Colmenares Karen
Purchasing
Seattle
King Steven
Seattle

Executive

Kochhar Neena
Seattle

Executive

NOMBRE
DEPARTAMENTO
---------------------------------------------- -----------------------------CIUDAD
-----------------------------De Haan Lex
Executive
Seattle
Greenberg Nancy
Seattle

Finance

Faviet Daniel
Seattle

Finance

NOMBRE
DEPARTAMENTO
---------------------------------------------- -----------------------------CIUDAD
-----------------------------Chen John
Finance
Seattle
Sciarra Ismael
Seattle

Finance

Urman Jose Manuel

Finance

Seattle
NOMBRE
DEPARTAMENTO
---------------------------------------------- -----------------------------CIUDAD
-----------------------------Popp Luis
Finance
Seattle
Higgins Shelley
Seattle

Accounting

Gietz William
Seattle

Accounting

5)
Reportar la clave y el nombre de la regin a la que pertenece la ciudad d
e Seattle.
SQL>
2
3
4
5

SELECT city Ciudad, regions.region_id Clave, region_name Region


FROM locations, regions, countries
WHERE locations.country_id = countries.country_id
AND countries.region_id = regions.region_id
AND city = 'Seattle';

CIUDAD
CLAVE REGION
------------------------------ ---------- ------------------------Seattle
2 Americas
6)

Reportar cuntos perodos laboral(es) ha tenido el empleado

SQL> SELECT COUNT(start_date) "Periodos Laborales"


2 FROM job_history
3 WHERE employee_id =
4
(SELECT employee_id FROM employees
5
WHERE first_name = 'Neena' AND last_name = 'Kochhar');
Periodos Laborales
-----------------2

Neena Koochar

S-ar putea să vă placă și