0% found this document useful (0 votes)
7 views5 pages

Tareabd

Uploaded by

Luis Zelaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Tareabd

Uploaded by

Luis Zelaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIVERSIDAD NACIONAL DE INGENIERÍA

ÁREA DE CONOCIMIENTO DE TECNOLOGÍA DE LA


INFORMACIÓN Y COMPUTACION

INGENIERIA DE SISTEMAS

BASE DE DATOS I

INTEGRANTES:

- LUIS ENMANUEL ZELAYA O`MEANY

GRUPO: 2M5-SIES
Comando en select:
SELECT FirstName, LastName, Title

FROM Employees;

SELECT ProductName, UnitPrice

FROM Products

WHERE UnitPrice > 50;

SELECT OrderID, OrderDate

FROM Orders

WHERE CustomerID = ‘ALFKI’;

Comandos con Update:


UPDATE Products

SET UnitPrice = UnitPrice * 1.10

WHERE Category = ‘Bebidas’;

UPDATE Customers

SET ContactName = ‘Ana Gonzalez’

WHERE CustomerID = ‘ALFKI’;

UPDATE Employees

SET Address = ‘123 New Street, New York, USA’

WHERE EmployeeID = 1;
Comando con Delete:
DELETE FROM Products

WHERE UnitsInStock = 0;

DELETE FROM Customers

WHERE CustomerID = ‘NEW01’;

DELETE FROM Orders

WHERE OrderDate < ‘2020-01-01’;

Operadores matemáticos:
SELECT ProductName,

CASE

WHEN Price > 30 THEN Price * 0.85

ELSE Price

END AS TotalPrice

FROM Products;

SELECT OrderID,

(UnitPrice * Quantity – Discount) AS TotalValue

FROM OrderDetails;

SELECT FirstName, LastName, Country


FROM Employees

WHERE Country = ‘USA’ OR Country = ‘UK’;

SELECT ProductName, UnitsInStock, Price

FROM Products

WHERE UnitsInStock < 20 AND Price > 40;

Funciones Agregadas (SUM, AVG, MIN, MAX, COUNT):


SELECT AVG(UnitPrice) AS AverageUnitPrice

FROM Products;

SELECT Category,

MIN(UnitPrice) AS MinUnitPrice,

MAX(UnitPrice) AS MaxUnitPrice

FROM Products

GROUP BY Category;

SELECT MIN(OrderDate) AS OldestOrder,

MAX(OrderDate) AS MostRecentOrder

FROM Orders;

SELECT CustomerID,

COUNT(OrderID) AS NumberOfOrders

FROM Orders

GROUP BY CustomerID;
Consultas con GroupBy, Having y Order By:
SELECT EmployeeID,

SUM(UnitPrice * Quantity) AS TotalSales

FROM OrderDetails

JOIN Orders ON OrderDetails.OrderID = Orders.OrderID

GROUP BY EmployeeID

ORDER BY TotalSales DESC;

SELECT CategoryID,

CategoryName,

AVG(Price) AS AveragePrice

FROM Products

JOIN Categories ON Products.CategoryID = Categories.CategoryID

GROUP BY CategoryID, CategoryName

HAVING AVG(Price) > 20

ORDER BY AveragePrice ASC;

You might also like