Está en la página 1de 6

-- 1.

Relacion de empleados que mas ventas han efectuado en el año 1998

select E.FirstName + ' ' + E.LastName as 'Empleado',SUM(OD.Quantity * OD.UnitPrice) as 'Total Ventas'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID inner join

Employees E on E.EmployeeID = O.EmployeeID

where DATEPART(year,O.OrderDate) = 1998

group by E.FirstName + ' ' + E.LastName

Order by SUM(OD.Quantity * OD.UnitPrice) desc

-- 2. Que cantidad se han vendido del producto 'Tofu' en el año 1997

select P.ProductName,SUM(OD.Quantity) as 'Cantidad'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID inner join Products P

on P.ProductID = OD.ProductID

where P.ProductName = 'Tofu' and DATEPART(year,O.OrderDate) = 1997

group by P.ProductName

-- 3. Que empresa es la que mas se ha demorado en la entrega de su mercaderia en 1998

select top 1 S.CompanyName, DATEDIFF(DAY,O.RequiredDate,O.ShippedDate) as 'Dias Demora'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Products P on P.ProductID = OD.ProductID inner join Suppliers S on S.SupplierID = P.SupplierID

where DATEPART(year,O.OrderDate) = 1998

group by S.CompanyName,O.RequiredDate,O.ShippedDate

order by DATEDIFF(DAY,O.RequiredDate,O.ShippedDate) desc

-- 4. Cuales son las ordenes que hayan superado el promedio de ventas del año 1998

select O.OrderID,SUM(OD.Quantity * OD.UnitPrice) as 'Monto'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID


inner join Products P on P.ProductID = OD.ProductID

where DATEPART(year,O.OrderDate) = 1998

group by O.OrderID

having SUM(OD.Quantity * OD.UnitPrice) > (select AVG(OD.Quantity * OD.UnitPrice)

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

where DATEPART(year,O.OrderDate) = 1998)

order by SUM(OD.Quantity * OD.UnitPrice) desc

-- 5. Montón de las ordenes despachadas a clientes de Lisboa y Sao Paulo

select C.City,SUM(OD.Quantity * OD.UnitPrice) as 'Monto'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Customers C on C.CustomerID = O.CustomerID

where C.City = 'Lisboa' or C.City = 'Sao Paulo'

group by C.City

order by SUM(OD.Quantity * OD.UnitPrice) desc

-- 6. Total de ventas por categorías de productos

select C.CategoryName,SUM(OD.Quantity * OD.UnitPrice) as 'Total Ventas'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Products P on P.ProductID = OD.ProductID inner join

Categories C on C.CategoryID = P.CategoryID

group by C.CategoryName

order by SUM(OD.Quantity * OD.UnitPrice) desc

-- 7. Cuales con las cinco empresas mas se han demorado en entregar su mercadería en 1998

select top 5 S.CompanyName, DATEDIFF(DAY,O.RequiredDate,O.ShippedDate) as 'Dias Demora'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Products P on P.ProductID = OD.ProductID inner join Suppliers S on S.SupplierID = P.SupplierID
where DATEPART(year,O.OrderDate) = 1998

group by S.CompanyName,O.RequiredDate,O.ShippedDate

order by DATEDIFF(DAY,O.RequiredDate,O.ShippedDate) desc

-- 8. Productos que están discontinuados o que están por debajo de su nivel de reorden y que hayan sido
despachados

select P.ProductName

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Products P on P.ProductID = OD.ProductID

where P.UnitsOnOrder <= P.ReorderLevel or P.Discontinued = 'true'

group by P.ProductName

order by P.ProductName asc

-- 9. Cantidad de artículos por proveedor

select S.CompanyName,SUM(OD.Quantity) as 'Cantidad'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Products P on P.ProductID = OD.ProductID inner join Suppliers S on S.SupplierID = P.SupplierID

group by S.CompanyName

order by SUM(OD.Quantity) desc

-- 10.Productos expendidos por proveedor en el año de 1997

select S.CompanyName,P.ProductName

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Products P on P.ProductID = OD.ProductID inner join Suppliers S on S.SupplierID = P.SupplierID

where DATEPART(year,O.OrderDate) = 1997

group by S.CompanyName,P.ProductName

order by S.CompanyName,P.ProductName
-- 11. Cual es el promedio de días que se demoran en entregar la mercadería por embarcación

select S.CompanyName,AVG(DATEDIFF(DAY,O.RequiredDate,O.ShippedDate)) as 'Dias Demora'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Shippers S on S.ShipperID = O.ShipVia

group by S.CompanyName

order by S.CompanyName

-- 12. Que empleados han superado el promedio de ventas en 1997

select E.FirstName + ' ' + E.LastName as 'Empleado',SUM(OD.Quantity * OD.UnitPrice) as 'Monto'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Employees E on E.EmployeeID = O.EmployeeID

where DATEPART(year,O.OrderDate) = 1997

group by E.FirstName + ' ' + E.LastName

having SUM(OD.Quantity * OD.UnitPrice) > (select AVG(OD.Quantity * OD.UnitPrice)

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

where DATEPART(year,O.OrderDate) = 1997)

order by SUM(OD.Quantity * OD.UnitPrice) desc

-- 13. Monto de las ordenes despachadas por proveedor en el primer semestre de 1997

select S.CompanyName,SUM(OD.Quantity * OD.UnitPrice) as 'Monto'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Products P on P.ProductID = OD.ProductID inner join Suppliers S on S.SupplierID = P.SupplierID

where DATEPART(year,O.OrderDate) = 1997 and (DATEPART(MONTH,O.OrderDate) >= 1 and


DATEPART(MONTH,O.OrderDate) <= 3)

group by S.CompanyName

order by SUM(OD.Quantity * OD.UnitPrice) desc

-- 14. cantidad de ordenes entregadas por proveedor en 1996


select S.CompanyName,SUM(OD.Quantity) as 'Cantidad'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Products P on P.ProductID = OD.ProductID inner join Suppliers S on S.SupplierID = P.SupplierID

where DATEPART(year,O.OrderDate) = 1996

group by S.CompanyName

order by SUM(OD.Quantity) desc

-- 15. cantidad de empleados por región

select R.RegionDescription,COUNT(E.EmployeeID) as 'Cantidad'

from Employees E inner join EmployeeTerritories ET on E.EmployeeID = ET.EmployeeID

inner join Territories T on T.TerritoryID = ET.TerritoryID

inner join Region R on R.RegionID = T.RegionID

group by R.RegionDescription

order by COUNT(E.EmployeeID) desc

-- 16. Producto que mas se ha vendido en 1997

select P.ProductName,SUM(OD.Quantity * OD.UnitPrice) as 'Total Ventas'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID

inner join Products P on P.ProductID = OD.ProductID

where DATEPART(year,O.OrderDate) = 1997

group by P.ProductName

order by SUM(OD.Quantity * OD.UnitPrice) desc

-- 17. en que día se vendió mas del producto 'Ikura'

select top 1 P.ProductName,CONVERT(DATE,O.OrderDate) as 'Fecha',

SUM(OD.Quantity * OD.UnitPrice) as 'Total Venta'

from Orders O inner join [Order Details] OD on O.OrderID = OD.OrderID


inner join Products P on P.ProductID = OD.ProductID

where P.ProductName = 'Ikura'

group by P.ProductName,O.OrderDate

order by SUM(OD.Quantity * OD.UnitPrice) desc