El Lenguaje Transact 2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

EL LENGUAJE TRANSACT-SQL 2

IBETH ASTRID CÁRDENAS PEÑARETE


40130

TRANSACT 2

CENTRO DE GESTIÓN DE MERCADOS, LOGÍSTICA Y TECNOLOGÍA DE


LA INFORMACIÓN
BASE DE DATOS
AGOSTO DE 2010
BOGOTÁ D.C.
EL LENGUAJE TRANSACT-SQL 2

IBETH ASTRID CÁRDENAS PEÑARETE


40130

PRESENTADO A:

SANDRA RUEDA

TRANSACT 2

CENTRO DE GESTIÓN DE MERCADOS, LOGÍSTICA Y TECNOLOGÍA DE


LA INFORMACIÓN
BASE DE DATOS
AGOSTO DE 2010
BOGOTÁ D.C.
select CompanyName,AVG (UnitPrice)
from Products P Inner join Suppliers S on P.SupplierId=S.SupplierId
group by CompanyName

select AVG ((UnitPrice* Quantity)- Discount)as promedio, SUM ((UnitPrice* Quantity)-


Discount) as total
from [Order Details] d Inner join dbo.Orders o on d.OrderID = o.OrderID
where MONTH(OrderDate) between 01 and 06 and YEAR (OrderDate) = 1997

select CompanyName,AVG (UnitPrice)


from Products P Inner join Suppliers S on P.SupplierId=S.SupplierId
group by CompanyName

select LastName , FirstName , SUM (Freight)


from [Employees] d Inner join dbo.Orders o on d.EmployeeID = o.EmployeeID
where (FirstName)like 'Nancy' and (LastName) like 'Davolio'
group by LastName,FirstName

select top 1 Min(OrderDate) AS [primer pedido]


from Orders

select count(OrderID) as total


from [Order Details]
HAVING SUM ((UnitPrice* Quantity)- Discount) > 2500

select LastName , FirstName , COUNT (s.EmployeeID) as [cantidad de pedidos]


from Employees P Inner join dbo.Orders S on P.EmployeeID=S.EmployeeID
group by LastName , FirstName
order by [cantidad de pedidos]

select p.EmployeeID, LastName , FirstName , CustomerID, SUM (Freight)


from Employees P Inner join dbo.Orders S on P.EmployeeID=S.EmployeeID
group by p.EmployeeID, LastName , FirstName, CustomerID
order by CustomerID

select p.EmployeeID, LastName,FirstName, AVG (Freight) as promedio,SUM


((UnitPrice* Quantity)- Discount) as total
from (Employees P Inner join dbo.Orders S on P.EmployeeID=S.EmployeeID) Inner
Join [Order Details] f on f.OrderID = s.OrderID
group by p.EmployeeID, LastName,FirstName
having SUM ((UnitPrice* Quantity)- Discount) > 30000

select ProductName ,UnitPrice,UnitsInStock,UnitsOnOrder


from dbo.Products
group by ProductName ,UnitPrice,UnitsInStock,UnitsOnOrder
having (UnitsInStock*0.75)>UnitsOnOrder

You might also like