Tecnico

Páginas: 9 (2008 palabras) Publicado: 13 de julio de 2013
Nortwhing
1.- seleccionar el detalle de las órdenes
Nombre de cliente, no. orden, fecha, total de aquellas ordenes cuyo monto sea mayor a 10000 para la tienda 2.
2.- seleccionar las 3 regiones que tengan las ventas mayores
3.- seleccionar el producto que tiene más ventas y el cliente que más ha comprado ese producto.
4.- seleccionar el producto que tiene las ventas más bajas.

useNorthwind
/*Rodolfo Irigoyen Cerón*/
/*1
SELECCIONAR EL DETALLE DE LAS ORDENES
NOMBRE DEL CLIENTE, NO_ORDEN, FECHA, TOTAL
DE AQUELLAS ORDENES CUYO MONTO SEA MAYOR A 10000 PARA LA TIENDA 2*/
select * from Orders
select * from Shippers
select*from [Order Details]
select*from Customers

select COMPANYNAME,ORD.CustomerID, ORD.OrderID, ORDERDATE, (UnitPrice*Quantity) importe, ShipVia
from OrdersORD INNER JOIN [Order Details] on [Order Details].OrderID=ORD.OrderID INNER JOIN
Customers CU ON CU.CUSTOMERID=ORD.CustomerID
where shipvia=2 and (UnitPrice*Quantity)>10000

select COMPANYNAME,ORD.CustomerID, ORD.OrderID, ORDERDATE, sum(UnitPrice*Quantity) importe, ShipVia
from Orders ORD INNER JOIN [Order Details] on [Order Details].OrderID=ORD.OrderID INNER JOIN
Customers CU ONCU.CUSTOMERID=ORD.CustomerID
where shipvia=2
group by COMPANYNAME,ORD.CustomerID, ORD.OrderID, ORDERDATE, shipvia
having sum(UnitPrice*Quantity)>10000
/*2
SELECCIONAR LAS TRES REGIONES QUE TENGAN VENTAS MAYORES
nota: la tabla region no se relaciona con la tabla donde se obtienen las ventas
por lo que se toma la tabla "orders" donde se encuentra un campo que hace mencion
a el campo region*/SELECT * FROM REGION
SELECT*FROM [Order Details]
SELECT*FROM Orders

SELECT TOP 3 SHIPREGION,SUM(UnitPrice*Quantity) FROM ORDERS INNER JOIN [Order Details]
ON Orders.OrderID=[Order Details].OrderID
GROUP BY ShipRegion ORDER BY sum(unitprice*quantity) desc

select top 3 Region.RegionID, SUM(UnitPrice*Quantity )importe from [Order Details]
inner join orders on Orders.OrderID=[OrderDetails].OrderID inner join EmployeeTerritories
on Orders.EmployeeID=EmployeeTerritories.EmployeeID
inner join Territories on EmployeeTerritories.TerritoryID=Territories.TerritoryID
inner join Region on Region.RegionID=Territories.RegionID
group by Region.RegionID order by importe desc
/*3
SELECCIONEAR EL PRODUCTO QUE TENGA MÁS VENTAS Y EL CLIENTE QUE MAS HA
COMPRADO ESE PRODUCTO*/

select*from Products
select*from Customers
select*from [Order Details]
select *from Orders


select [Order Details].productid, productname, companyname, SUM([Order Details].Quantity) nono
from Orders Ord inner join Customers Cus on
Ord.CustomerID=Cus.CustomerID inner join [Order Details] on
Ord.OrderID=[Order Details].OrderID inner join Products Pro on
Pro.ProductID=[Order Details].ProductIDwhere exists (select top 1 ProductID, SUM(QUANTITY) FROM [Order Details]
GROUP BY ProductID order by 2 desc)
GROUP BY [Order Details].productid,ProductName, CompanyName
ORDER BY SUM(Quantity) desc
/*producto mas vendido*/
select top 1 ProductID, SUM(QUANTITY) FROM [Order Details]
GROUP BY ProductID order by 2 desc
/*nnnn*/
select top 1 cu.customerid,companyname,od.ProductID,SUM(quantity)cantidad,ProductName
from Customers cu
inner join Orders ord on cu.CustomerID=ord.CustomerID
inner join [Order Details] od
on od.OrderID=ord.OrderID
inner join Products pro on od.ProductID=pro.ProductID
where od.ProductID in(select p.prod from
(select top 1 od2.productid as prod, SUM(quantity)cant from [Order Details] od2
group by ProductID order by 2 desc ) p )
group by cu.customerid,companyname, od.ProductID, ProductName
order by cantidad desc



/*4
SELECCIONAR EL PROVEDOR DEL PRODUCTO QUE TIENE LAS VENTAS MAS BAJAS*/
select*from Suppliers
select*from Products
select*from [Order Details]

select top 1 companyname,ProductName, sum(quantity)
from Suppliers Su inner join Products Pro on
Su.SupplierID=Pro.SupplierID inner join [Order Details] ON
[Order...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Tecnica
  • Tecnico
  • Tecnicas
  • Tecnicas
  • Tecnico
  • Tecnicas
  • Tecnico
  • Tecnico

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS