resumida clase 3
This commit is contained in:
@@ -43,3 +43,41 @@ FROM (
|
|||||||
) AS d
|
) AS d
|
||||||
GROUP BY d.DepartamentoId;
|
GROUP BY d.DepartamentoId;
|
||||||
#+end_src
|
#+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
|
||||||
|
|||||||
Reference in New Issue
Block a user