Professional Documents
Culture Documents
1.
2.
3.
4.
5.
6.
7.
8.
9.
Mostrar los empleados con la cantidad de ventas que tiene cada uno.
10.
11.
12.
13.
vida de la empresa.
14.
de rdenes.
15.
16.
17.
SOLUCIN
--1
select count(*) as numeroEmpleados
from Employees
--2
select COUNT(*) from Customers
select COUNT(*) from Suppliers
--3
select e.EmployeeID, LastName+','+FirstName as NOMBRES, count(p.Pro
ductID) ascantProductos
from Employees as e
inner join Orders as o
on o.EmployeeID = e.EmployeeID
inner join [Order Details] as od
on od.OrderID = o.OrderID
inner join Products as p
on p.ProductID = od.ProductID
group by e.EmployeeID, LastName+','+FirstName
order by e.EmployeeID
--4
select s.SupplierID, CompanyName, count(ProductID)
from Suppliers as s
inner join Products as p
on p.SupplierID = s.SupplierID
group by s.SupplierID, CompanyName
from Suppliers as s
inner join Products as p
on p.SupplierID = s.SupplierID
order by s.SupplierID
--5
select top 1 CategoryID, count(ProductID)
from Products
group by CategoryID
order by count(ProductID) desc
--6
select OrderID, sum(UnitPrice*Quantity) as total
from [Order Details]
group by OrderID
--7
select avg(UnitPrice*Quantity)
from [Order Details]
--8
select s.SupplierID, CompanyName, max(UnitPrice) as maxPrecio, min(U
nitPrice) asminPrecio
from Suppliers as s
inner join Products as p
on p.SupplierID = s.SupplierID
--9
select e.EmployeeID, LastName+','+FirstName as NOMBRES, sum(UnitPri
ce*Quantity)
from Employees as e
inner join Orders as o
on o.EmployeeID = e.EmployeeID
inner join [Order Details] as od
on od.OrderID = o.OrderID
group by e.EmployeeID, LastName+','+FirstName
--10
select top 1 p.ProductID, sum(od.UnitPrice*Quantity)
from Products as p
inner join [Order Details] as od
on od.ProductID = p.ProductID
group by p.ProductID
order by sum(od.UnitPrice*Quantity) desc
--11
select top 1 p.ProductID, sum(od.UnitPrice*Quantity)
from Products as p
inner join [Order Details] as od
on od.ProductID = p.ProductID
group by p.ProductID
order by sum(od.UnitPrice*Quantity)
--12
select top 1 OrderDate, sum(UnitPrice*Quantity) as VENTAS
from Orders as o
inner join [Order Details] as od
on od.OrderID = o.OrderID
group by OrderDate
order by sum(UnitPrice*Quantity) desc
--13
select c.CustomerID, CompanyName, sum(UnitPrice*Quantity) COMPRAS
from Customers as c
inner join Orders as o
on o.CustomerID = c.CustomerID
inner join [Order Details] as od
on od.OrderID = o.OrderID
group by c.CustomerID, CompanyName
--14
select top 10
c.CustomerID, CompanyName, sum(UnitPrice*Quantity) COMPRAS
from Customers as c
inner join Orders as o
on o.CustomerID = c.CustomerID
inner join [Order Details] as od
on od.OrderID = o.OrderID
group by c.CustomerID, CompanyName
--15
select top 3
e.EmployeeID, LastName+','+FirstName as NOMBRES, sum(Quantity*Uni
tPrice)
from Employees as e
inner join Orders as o
on o.EmployeeID = e.EmployeeID
inner join [Order Details] as od
on od.OrderID = o.OrderID
group by e.EmployeeID, LastName+','+FirstName
order by sum(Quantity*UnitPrice) desc
--16
select e.EmployeeID, LastName+','+FirstName as NOMBRES, year(Order
Date) as ANIO,sum(Quantity*UnitPrice) as VENTAS
from Employees as e
inner join Orders as o
on o.EmployeeID = e.EmployeeID
inner join [Order Details] as od
on od.OrderID = o.OrderID
group by e.EmployeeID, LastName+','+FirstName, year(OrderDate)
order by e.EmployeeID
--17