Skip to content

Commit 6722346

Browse files
Update Advanced SQL Puzzles Solutions.sql
1 parent df63ec5 commit 6722346

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

Advanced SQL Puzzles/Advanced SQL Puzzles Solutions.sql

+23-14
Original file line numberDiff line numberDiff line change
@@ -1559,15 +1559,15 @@ Answer to Puzzle #33
15591559
Deadlines
15601560
*/----------------------------------------------------
15611561

1562-
DROP TABLE IF EXISTS #OrderFulfillments;
1562+
DROP TABLE IF EXISTS #Orders;
15631563
DROP TABLE IF EXISTS #ManufacturingTimes;
15641564
GO
15651565

1566-
CREATE TABLE #OrderFulfillments
1566+
CREATE TABLE #Orders
15671567
(
15681568
OrderID VARCHAR(100) PRIMARY KEY,
15691569
ProductID VARCHAR(100),
1570-
DaysToBuild INTEGER
1570+
DaysToDelivery INTEGER
15711571
);
15721572
GO
15731573

@@ -1580,7 +1580,7 @@ PRIMARY KEY (PartID, ProductID)
15801580
);
15811581
GO
15821582

1583-
INSERT INTO #OrderFulfillments VALUES
1583+
INSERT INTO #Orders VALUES
15841584
('Ord893456','Widget',7),
15851585
('Ord923654','Gizmo',3),
15861586
('Ord187239','Doodad',9);
@@ -1606,17 +1606,17 @@ FROM #ManufacturingTimes b
16061606
GROUP BY ProductID
16071607
)
16081608
SELECT a.*
1609-
FROM #OrderFulfillments a INNER JOIN
1610-
cte_Max b ON a.ProductID = b.ProductID AND a.DaysToBuild >= b.MaxDaysToManufacture;
1609+
FROM #Orders a INNER JOIN
1610+
cte_Max b ON a.ProductID = b.ProductID AND a.DaysToDelivery >= b.MaxDaysToManufacture;
16111611
GO
16121612

16131613
--Solution 2
16141614
--ALL
16151615
SELECT a.*
1616-
FROM #OrderFulfillments a
1617-
WHERE DaysToBuild >= ALL( SELECT DaysToManufacture
1618-
FROM #ManufacturingTimes b
1619-
WHERE a.ProductID = b.ProductID);
1616+
FROM #Orders a
1617+
WHERE DaysToDelivery >= ALL(SELECT DaysToManufacture
1618+
FROM #ManufacturingTimes b
1619+
WHERE a.ProductID = b.ProductID);
16201620
GO
16211621

16221622
/*----------------------------------------------------
@@ -1636,13 +1636,22 @@ Amount MONEY
16361636
GO
16371637

16381638
INSERT INTO #Orders VALUES
1639-
('Ord143937',1001,25),('Ord789765',1001,50),
1640-
('Ord345434',2002,65),('Ord465633',3003,50);
1639+
('Ord143937',1001,25),('Ord789765',1001,50),('Ord345434',2002,65),('Ord465633',3003,50);
1640+
GO
1641+
1642+
SELECT OrderID,
1643+
CustomerID,
1644+
Amount
1645+
FROM #Orders
1646+
WHERE NOT(CustomerID = 1001 AND Amount = 50);
16411647
GO
16421648

1643-
SELECT OrderID,CustomerID, Amount
1649+
SELECT OrderID,
1650+
CustomerID,
1651+
Amount
16441652
FROM #Orders
1645-
WHERE NOT(CustomerID = 1001 AND OrderID = 'Ord789765');
1653+
WHERE CONCAT(CustomerID, Amount) <> '100150.00'
1654+
ORDER BY 2
16461655
GO
16471656

16481657
/*----------------------------------------------------

0 commit comments

Comments
 (0)