Está en la página 1de 13

INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO

LIZBETH PATRICIA CHINCHERO TOAQUIZA


REDES Y TELECOMUNICACIONES
--1.- Consultar el máximo y mínimo precio de los productos por categoría, mostrar el nombre de la categoría.

select C.CategoryName,max(P.unitprice) as Maximo, min (P.Unitprice) as Minimo


from Categories C inner join Products P on C.CategoryID=P.CategoryID
group by C.CategoryName
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--2.- Crear un trigger de modo que no acepte un determinado valor al insertar un registro en Proveedores,
--escoja ud el atributo y el valor a controlar

create trigger trig_control_pro


on customers
for insert
as
declare @city varchar (50)
select @city= City from inserted
if @city like '%Cuenca%'
begin
print 'Cuidad no permitida'
rollback transaction
end

Insert into Customers values ('ATIK','COMPUTO','BRYAN','OWNER','Riobamba','Cuenca','null','1234','Ecuador'


,'4589764','0987350150')
select *from Customers
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--3. Seleccionar las categorías que tengan más 5 productos. Mostrar el nombre de la categoría y el número de productos.

select C.CategoryName, count(P.CategoryID) as 'Cantidad'


from Products P inner join Categories C on P.CategoryID=C.CategoryID
group by C.CategoryName
having count(P.CategoryID)>5
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--4.- Consultar todos los productos de las categorías confecciones, alimentos de mar y granos/cereales

select P.ProductName
from Products P inner join Categories C on P.CategoryID=C.CategoryID
group by C.CategoryName,P.ProductName
having C.CategoryName like '%Confections%' or C.CategoryName like '%Seafood%' or
C.CategoryName like '%Grains/Cereals%'
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--5.-Calcular cuántos proveedores existen en cada Ciudad y País.

select S.City,Count (S.City)as 'Cantidad', s.Country, count (s.Country) as 'Cantidad'


From Suppliers S
Group by S.City,S.Country
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--6.- Calcular el stock total de los productos por cada categoría. Mostrar el nombre de
--la categoría y el stock por categoría.
Select C.CategoryName,sum(P.UnitPrice) as Stock
from Categories C inner join Products P on P.CategoryID=C.CategoryID
group by C.CategoryName
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--7.-Calcular el stock total de los productos por cada categoría. Mostrar el nombre de la categoría y
--el stock por categoría. Solamente las categorías 2, 5 y 8.
select c.CategoryID,c.CategoryName, sum(p.UnitsInStock) as 'Stock total'
from products as p
inner join Categories as c on p.CategoryID=c.CategoryID
where c.CategoryID in( 2, 5 , 8)
group by c.CategoryID,c.CategoryName
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--8.- Obtener el nombre del empleado, nombre de proveedor, nombre del cliente y
--el nombre de los productos que están en la orden 10484.
select c.ContactName,s.ContactName, e.FirstName, p.ProductName,
o.OrderID
from orders as O
inner join Employees E on E.EmployeeID=O.EmployeeID
inner join Customers C on C.CustomerID = O.CustomerID
inner join OrderDetails OD on OD.OrderID=O.OrderID
inner join Products P on p.ProductID=od.ProductID
inner join Suppliers S on S.SupplierID=P.SupplierID
where o.OrderID = 10484
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--9.- muestre los productos cuyo precio es mayor al promedio de precio de todos los productos
select p.ProductName , P.UnitPrice
from Products P
where P.UnitPrice>(select AVG(P1.unitprice) from Products P1)
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--10.- Seleccionar el código de la orden de compra, el nombre de la compañía del cliente,
--la fecha de la orden de compra, código del producto, cantidad pedida del producto, nombre del producto,
--el nombre de la compañía proveedora y la ciudad del proveedor.
--Donde el nombre de la compania del cliente empiece con las letras de la "h" a la "m",
--ademas que la cantidad de producto sea de 30, 40 , 50 y 60 unidades, y finalmente que las ordenes sean
--de todos los meses de abril de cualquier anio.

select o.OrderID ,c.CompanyName,O.OrderDate,O.OrderID,P.ProductID,OD.Quantity,


P.ProductName,S.CompanyName,S.City
from customers C
inner join Orders O on o.CustomerID=c.CustomerID
inner join OrderDetails as OD on OD.OrderID=O.OrderID
inner join Products P on P.ProductID=OD.ProductID
inner join Suppliers S on S.SupplierID=P.SupplierID
where (C.CompanyName like '[h-m]%')and OD.Quantity
in (30,40,50,60) and MONTH (O.OrderDate)='04'
order by C.CompanyName
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
INSTITUTO TECNOLOGICO SUPERIOR QUITO METROPOLITANO
LIZBETH PATRICIA CHINCHERO TOAQUIZA
REDES Y TELECOMUNICACIONES
--11.- Implemente un Procedimiento almacenado para mostrar los datos de los productos de una categoría ingresada por teclado.

create procedure sp_datos

@categoria int
as
select p.ProductID, p.ProductName, p.UnitPrice, p.UnitsInStock, p.UnitsOnOrder, p.CategoryID, p.Discontinued,
p.QuantityPerUnit
from Categories c inner join Products P on c.CategoryID=p.CategoryID
where c.CategoryID=@categoria

sp_datos 1

También podría gustarte