Skip to content

Commit 32a11aa

Browse files
committed
comitting new adventure work scripts
1 parent af217ae commit 32a11aa

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

scripts/Adventureworks/joins.sql

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
BEGIN TRANSACTION
2+
3+
CREATE TABLE Customers
4+
(
5+
Id INT IDENTITY(1,1),
6+
Name NVARCHAR(50)
7+
8+
CONSTRAINT PK_Customers PRIMARY KEY CLUSTERED (Id)
9+
)
10+
11+
CREATE TABLE Orders
12+
(
13+
Id INT IDENTITY(1,1),
14+
CustomerId INT,
15+
OrderDate DATETIME
16+
17+
CONSTRAINT PK_Orders PRIMARY KEY CLUSTERED (Id)
18+
CONSTRAINT FK_Customers FOREIGN KEY (CustomerId) REFERENCES Customers (Id)
19+
)
20+
21+
INSERT INTO Customers (Name) VALUES ('David'), ('Jack'), ('Jake'), ('John'), ('Greg'), ('Bart')
22+
INSERT INTO Orders (CustomerId) VALUES (1), (2), (2), (5), (5), (1), (NULL)
23+
24+
SELECT Orders.Id AS 'OrderId'
25+
, Customers.Id AS'CustomerId'
26+
, Customers.Name AS 'CustomerName'
27+
FROM Orders FULL JOIN Customers ON Orders.CustomerId = Customers.Id
28+
ORDER BY OrderId
29+
30+
SELECT Orders.Id 'OrderId', Customers.Id 'CustomerId', Customers.Name 'CustomerName'
31+
FROM Customers FULL JOIN Orders ON Customers.Id = Orders.CustomerId
32+
ORDER BY OrderId
33+
34+
ROLLBACK TRANSACTION
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
USE AdventureWorks;
2+
3+
--SELECT line subquery
4+
--SELECT Name, ListPrice, (SELECT AVG(ListPrice) AS Average FROM Production.Product)
5+
--FROM Production.Product
6+
7+
--FROM Line subquery
8+
--;WITH subquery AS
9+
--(
10+
-- SELECT ProductSubcategoryID, AVG(Product.ListPrice) AS Avg
11+
-- FROM Production.Product
12+
-- GROUP BY ProductSubcategoryID
13+
--)
14+
--SELECT p.Name, p.ListPrice, subquery.Avg, p.ListPrice - subquery.Avg AS Diff
15+
--FROM Production.Product p
16+
--INNER JOIN subquery ON p.ProductSubcategoryID = subquery.ProductSubcategoryID
17+
18+
--WHERE Line subquery
19+
--SELECT FirstName, LastName, EmailAddress
20+
--FROM Person.Contact p
21+
--WHERE p.ContactID IN (SELECT soh.ContactID FROM Sales.SalesOrderHeader soh)
22+
23+
--EXISTS
24+
--SELECT FirstName, LastName, EmailAddress
25+
--FROM Person.Contact p
26+
--WHERE EXISTS (SELECT soh.ContactID FROM Sales.SalesOrderHeader soh WHERE soh.ContactID = p.ContactID)
27+
28+
--Any/All
29+
SELECT Name
30+
FROM Production.Product
31+
WHERE ListPrice >= ANY
32+
(SELECT MAX (ListPrice)
33+
FROM Production.Product
34+
GROUP BY ProductSubcategoryID) ;
35+
36+
--UNIONS
37+
--SELECT FirstName + ' ' + LastName AS 'FullName', EmailAddress
38+
--FROM Person.Contact p
39+
--UNION ALL
40+
--SELECT ReviewerName, EmailAddress
41+
--FROM Production.ProductReview

scripts/pluralsight_script.sql

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ INNER JOIN Orders
6363
ON PO.OrderId = Orders.Id
6464
INNER JOIN Customers
6565
ON Orders.CustomerId = Customers.Id
66+
Where Products.Id IN(1,2)
6667
ORDER BY Orders.Id
6768

69+
6870
ROLLBACK TRANSACTION

0 commit comments

Comments
 (0)