Professional Documents
Culture Documents
BASE DE DATOS 1
SEMESTRE: SEGUNDO
ANDRÉS DE LA CADENA
1. EJERCICIO 1 - -- Mostrar a todos los empleados que se encuentran en el departamento de manufactura y de
aseguramiento de la calidad.
select e.BusinessEntityID, e.*,
d.Name
from HumanResources.Employee e
inner join
HumanResources.EmployeeDepartmentHistory h
on e.BusinessEntityID = h.BusinessEntityID
inner join HumanResources.Department d
on d.DepartmentID = h.DepartmentID
and h.EndDate is null
and d.Name in ('Quality Assurance', 'Production');
2. EJERCICIO 2 - Indicar el listado de los empleados del sexo masculino y que son solteros
select e.BusinessEntityID, e.*,
d.Name
from HumanResources.Employee e
inner join
HumanResources.EmployeeDepartmentHistory h
on e.BusinessEntityID = h.BusinessEntityID
inner join HumanResources.Department d
on d.DepartmentID = h.DepartmentID
and h.EndDate is null
and d.Name in ('Quality Assurance', 'Production')
select * from HumanResources.Employee where Gender = 'M' and MaritalStatus = 'S';
3. EJERCICIO - Empleados cuyo apellido sea con la letra “S”
select * from HumanResources.Employee e
inner join Person.Person p
on e.BusinessEntityID = p.BusinessEntityID
and p.LastName like '%S%';
4. EJERCICIO 4
select pp.*,ps.Name from HumanResources.Employee he
inner join Person.Person pp
on pp.BusinessEntityID = he.BusinessEntityID
inner join Person.BusinessEntityAddress pb
on pb.BusinessEntityID = pp.BusinessEntityID
inner join Person.Address pa
on pa.AddressID = pb.AddressID
inner join Person.StateProvince ps
on ps.StateProvinceID = pa.StateProvinceID
and ps.Name = 'Florida';
5. EJERCICIO 5 - La suma de las ventas hechas por cada empleado, y agrupadas por año
select pp.FirstName, sum(SalesQuota) as total_vendido,
year(QuotaDate) as año
from Sales.SalesPersonQuotaHistory qh
inner join Person.Person pp
on qh.BusinessEntityID = pp.BusinessEntityID
group by pp.BusinessEntityID, year(QuotaDate), pp.FirstName
order by pp.BusinessEntityID;