You are on page 1of 4

Consulta 1 select EmployeeId,Sum(Freight) as Total,AvG(Freight) as Promedio From orders Group by EmployeeId Having AvG(Freight) between 50 and 90 Order by Sum(Freight)Desc

Consulta 2 Select EmployeeID, SUM(Freight) as Total, AVG(Freight) as Promedio From Orders where Year(ShippedDate)=1998 and DAY(ShippedDate)<=15 and MONTH(ShippedDate)=1 Group by EmployeeID Having AVG(Freight) between 50 and 90 Order by SUM(Freight) desc Consulta 3 Select A.ProductName, B.CompanyName,B.ContactName From Products A join Suppliers B on (A.SupplierId = B.supplierID) Join Categories C on (C.CategoryId = A.CategoryId) where C.Description like 'S%' and C.description like '%ee%' and A.ReorderLevel <= 25 and A.SupplierId % 2 = 0 Consulta 4 Select Count(*), f(Count(*)/2) From Products A join Suppliers B on (A.SupplierId = B.supplierID) Join Categories C on (C.CategoryId = A.CategoryId) where C.Description like 'S%' and C.description like '%ee%' and A.ReorderLevel <= 25 and A.SupplierId % 2 = 0

Consulta 5 Select Distinct A.FirstName From Employees A join Employeeterritories B on (A.EmployeeId = B.EmployeeId) join Territories C on ( B.TerritoryId = C.TerritoryId) join Region D on (D.RegionId = C.RegionId) where D.RegionDescription = 'Eastern' and A.TitleOfCourtesy <> 'Mrs.' Consulta 6 Select case when month(birthdate) = 3 day(birthdate) <= 20 then when month(birthdate) = 4 day(birthdate) <= 20 then when month(birthdate) = 5 day(birthdate) <= 20 then when month(birthdate) = 6 day(birthdate) <= 22 then when month(birthdate) = 7 day(birthdate) <= 22 then when month(birthdate) = 8 day(birthdate) <= 22 then and day(birthdate) 'Aries' and day(birthdate) 'Tauros' and day(birthdate) 'Geminis' and day(birthdate) 'Cancer' and day(birthdate) 'Leo' and day(birthdate) 'Virgo' >= 20 or month(birthdate) = 4 and >= 21 or month(birthdate) = 5 and >= 21 or month(birthdate) = 6 and >= 21 or month(birthdate) = 7 and >= 23 or month(birthdate) = 8 and >= 23 or month(birthdate) = 9 and

when month(birthdate) = 9 and day(birthdate) >= 23 or day(birthdate) <= 23 then 'Libra' when month(birthdate) = 10 and day(birthdate) >= 24 or d day(birthdate) <= 21 then 'Escorpion' when month(birthdate) = 11 and day(birthdate) >= 22 or d day(birthdate) <= 21 then 'Sagitario' when month(birthdate) = 12 and day(birthdate) >= 22 or day(birthdate) <= 19 then 'Capricornio' when month(birthdate) = 1 and day(birthdate) >= 20 or day(birthdate) <= 19 then 'Acuario' when month(birthdate) = 2 and day(birthdate) >= 20 or day(birthdate) <= 20 then 'Piscis' end, count(*) From employees group by case when month(birthdate) = 3 and day(birthdate) >= 20 or day(birthdate) <= 20 then 'Aries' when month(birthdate) = 4 and day(birthdate) >= 21 or day(birthdate) <= 20 then 'Tauros' when month(birthdate) = 5 and day(birthdate) >= 21 or day(birthdate) <= 20 then 'Geminis' when month(birthdate) = 6 and day(birthdate) >= 21 or day(birthdate) <= 22 then 'Cancer' when month(birthdate) = 7 and day(birthdate) >= 23 or day(birthdate) <= 22 then 'Leo' when month(birthdate) = 8 and day(birthdate) >= 23 or day(birthdate) <= 22 then 'Virgo' when month(birthdate) = 9 and day(birthdate) >= 23 or day(birthdate) <= 23 then 'Libra' when month(birthdate) = 10 and day(birthdate) >= 24 or d day(birthdate) <= 21 then 'Escorpion' when month(birthdate) = 11 and day(birthdate) >= 22 or d day(birthdate) <= 21 then 'Sagitario' when month(birthdate) = 12 and day(birthdate) >= 22 or day(birthdate) <= 19 then 'Capricornio' when month(birthdate) = 1 and day(birthdate) >= 20 or day(birthdate) <= 19 then 'Acuario' when month(birthdate) = 2 and day(birthdate) >= 20 or day(birthdate) <= 20 then 'Piscis' end having count(*) >1 Consulta 7

month(birthdate) = 10 and month(birthdate) = 11 an month(birthdate) = 12 an month(birthdate) = 1 and month(birthdate) = 2 and month(birthdate) = 3 and

month(birthdate) = 4 and month(birthdate) = 5 and month(birthdate) = 6 and month(birthdate) = 7 and month(birthdate) = 8 and month(birthdate) = 9 and month(birthdate) = 10 and month(birthdate) = 11 an month(birthdate) = 12 an month(birthdate) = 1 and month(birthdate) = 2 and month(birthdate) = 3 and

Select Year(A.OrderDate) as ao , C.companyName as Compaia ,Sum(B.Quantity * B.Unit Price) as Importe From Orders A join "order Details" B on (A.orderid = B.orderid) join Customers C on (A.CustomerID = C.CustomerID) join Products D on (D.ProductID = B.ProductID) join Categories E on ( E.CategoryID = D.CategoryID) where (year(OrderDate) = '1996' and E.CategoryName = 'seafood' and (C.Country =' Sweden' or C.Country ='Australia') ) or year(OrderDate) = '1997' Group by year(A.OrderDate),C.CompanyName having sum(B.Quantity * B.UnitPrice) < 400 order by ao,Importe desc consulta 8

Select A.title,case A.type when 'Business' then 'Negocios' else A.type end as Tipo,(C.au_fname + ' ' + C.au_lname) as Nombre From Titles A join TitleAuthor B on (A.title_id = B.title_id) join authors C on (C.au_id = B.au_id) where C.State = 'CA' and C.city like 'San%' order by Nombre desc,tipo Consulta 9 Select A.title as Titulo, Sum(B.qty)as Vendidos From titles A join Sales B on (A.title_id = B.title_id) Where not Left(A.title,1) in ('A','E','I','O','U') Group by A.title having Avg(B.qty) <> Sum(B.qty) Consulta 10 Select Top 1 A.fname as Nombre, (C.price)* Count(D.qty) as Vendido From employee A Join publishers B on (A.pub_id=B.pub_id) Join titles C on (B.pub_id=C.pub_id) Join sales D on (C.title_id=D.title_id) Join titleauthor E on (C.title_id=E.title_id) Join authors F on (E.au_id=F.au_id) Join stores G on (G.stor_id=D.stor_id) Where (F.state='CA' or F.state='UT') and F.city like '%k%' and LEFT(F.city,1)not in ('W') and G.state='WA' and (Month(D.ord_date)=9 and DAY(D.ord_date) between 13 and 16) and A.minit='H' Group by A.fname, C.price Order By (C.price)* Count(D.qty) desc Consulta 11

Select C.title as Titulo From authors A Join titleauthor B on (A.au_id=B.au_id) Join titles C on (B.title_id=C.title_id) Join sales D on (D.title_id=C.title_id) Join stores E on (D.stor_id=E.stor_id) Where A.state=E.state Group by C.title consulta 12 Select A.CompanyName as 'Nombre De Compaia' From Customers A Join Orders B on (A.CustomerID=B.CustomerID) Join "Order Details" C on (B.OrderID=C.OrderID) Join Products D on (C.ProductID=D.ProductID) Join Suppliers E on (D.ProductID=D.ProductID) Where A.Country='Mexico' and (E.Country= 'USA' or E.Country= 'Norway' or E.Count

ry= 'Netherlands' or E.Country= 'Sweden') Group by A.CompanyName

You might also like