resumida clase 3

This commit is contained in:
2025-05-12 14:23:22 -03:00
parent 52395bd81d
commit 0c425af938

View File

@@ -43,3 +43,41 @@ FROM (
) AS d
GROUP BY d.DepartamentoId;
#+end_src
* clase3 Subconsulta con update, insert, delete
** insert
#+begin_src sql
INSERT INTO Customers
(CustomerID,
CompanyName,
ContactName,
ContactTitle,
Address, City, Region, PostalCode, Country, Phone, Fax)
SELECT
SUBSTRING(firstname, 1, 3) + SUBSTRING(lastname, 1, 2) AS CustomerID,
lastname AS CompanyName,
firstname AS ContactName,
title AS ContactTitle,
address, city, region, postalcode, country, homephone AS Phone, NULL AS Fax
FROM Employees;
#+end_src
** update
#+begin_src sql
DELETE FROM [Order Details]
WHERE OrderID IN (
SELECT OrderID
FROM Orders
WHERE OrderDate = '2005-04-14'
);
#+end_src
** delete
#+begin_src sql
UPDATE Products
SET UnitPrice = UnitPrice + 2
WHERE SupplierID IN (
SELECT SupplierID
FROM Suppliers
WHERE Country = 'USA'
);
#+end_src