0% found this document useful (0 votes)
63 views6 pages

2-14 Merged

This document describes an activity involving SQL joins on a database of human resources information. It provides 10 questions to answer using SQL joins on tables such as regions, countries, locations, departments, jobs, job history, and employees. The questions include obtaining counts of personnel movements by region, salary details for specific departments, average payrolls by region, departments with payrolls above averages, and employee details grouped by department.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views6 pages

2-14 Merged

This document describes an activity involving SQL joins on a database of human resources information. It provides 10 questions to answer using SQL joins on tables such as regions, countries, locations, departments, jobs, job history, and employees. The questions include obtaining counts of personnel movements by region, salary details for specific departments, average payrolls by region, departments with payrolls above averages, and employee details grouped by department.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Ingeniería de Software

Modalidad virtual

Grupo: I*5SW2 Nombre del Maestro: Torres Knight Ricardo Ramon

Matrícula:355177 Nombre del Alumno: Mertinez Gamez Brayan

ACTIVIDAD: FECHA ENTREGA: 12/03/2023


2.14
TITULO: SQL Join II

OBJETIVO:

Aplicar sentencias Join en SQL

DESCRIPCIÓN:

Conteste los siguientes requerimientos de información sobre la base de datos de Recursos Humanos(HR)
en Oracle SQL join
1. Obtener el no. de movimientos de personal por región (region_name, no.
movimientos) – cambio de puesto o departamento.

SELECT region_id, region_name, COUNT(*) AS "No. Mov" FROM regions

JOIN countries USING (region_id)

JOIN locations USING (country_id)

JOIN departments USING (location_id)

JOIN job_history USING (department_id)

GROUP BY region_id, region_name

2. Obtener del departamento ‘Sales’, el job_id, job_title, el salario mínimo y


máximo de los puestos de dicho departamento.

SELECT job_history.job_id, job_title, max_salary, min_salary FROM jobs

JOIN job_history ON jobs.job_id = job_history.job_id

JOIN departments ON departments.department_id =

job_history.department_id

WHERE departments.department_name LIKE 'Sales'

3. Obtener de cada región la nómina promedio (región_name,


nomina_promedio)

SELECT region_name, AVG(salary) FROM regions


JOIN COUNTRIES USING(REGION_ID)

JOIN locations USING(country_id)

JOIN departments USING(location_id)

JOIN employees USING(department_id)

GROUP BY regions.region_name

4. Obtener el department_name de los departamentos que tienen una nómina


mayor que el promedio de la nómina del departamento de

‘Human Resources’.

SELECT department_name, SUM (salary) FROM DEPARTMENTS

JOIN employees USING (department_id)

GROUP BY department_name HAVING SUM (salary) > (select avg(salary)

FROM DEPARTMENTS

JOIN employees USING (department_id)

GROUP BY department_name HAVING department_name LIKE 'Human

Resources')
5. Obtener el department_id, department_name, no. de empleados, nómina
total, nómina promedio, salario mayor y menor para cada departamento.

SELECT employees.department_id, departments.department_name,

COUNT(employee_id), SUM(employees.salary),

ROUND(AVG(employees.salary), 2), ROUND(MAX(employees.salary),2),

MIN(employees.salary) FROM employees

INNER JOIN departments ON(employees.department_id =

departments.department_id)

GROUP BY employees.department_id, departments.department_name

6. Obtener el department_name de los departamentos donde el salario mayor y


menor son iguales

SELECT departments.department_name, MAX(employees.salary),

MIN(employees.salary) FROM employees

INNER JOIN departments ON (employees.department_id =

departments.department_id)

GROUP BY departments.department_name

HAVING (MAX (employees.salary) = MIN(employees.salary))

ORDER BY (MAX (employees.salary)) DESC


7. Obtener por rango de salario de los diferentes puestos de las tablas de Jobs,
el no. de empleados (min_salary, max_salary, no. de empleados).

SELECT jobs.job_id, jobs.min_salary, jobs.max_salary, (SELECT

COUNT(employee_id) FROM employees

WHERE salary BETWEEN jobs.min_salary AND jobs.max_salary)FROM jobs

ORDER BY jobs.job_id ASC

8. Obtener la región_name de las regiones donde existe el puesto


‘Programmer’. SELECT regions.region_name,
COUNT(employees.employee_id) FROM employees

INNER JOIN jobs USING (job_id)

INNER JOIN departments USING (department_id)

INNER JOIN locations USING (location_id)

INNER JOIN countries USING (country_id)

INNER JOIN regions USING (region_id) WHERE jobs.job_title =

'Programmer'
GROUP BY regions.region_name

9. Obtener las regiones con más de 40 empleados en su nómina


(region_name, no. empleados) SELECT regions.region_name,
COUNT(employees.employee_id) FROM employees

INNER JOIN departments USING (department_id)

INNER JOIN locations USING (location_id)

INNER JOIN countries USING (country_id)

INNER JOIN regions USING (region_id)

GROUP BY regions.region_name HAVING COUNT(employee_id) > 40

10.Obtener los empleados que son subordinados directos del jefe del
departamento donde laboran (deparment_name, nombre_jefe,
nombre_subordinado).

You might also like