File tree 1 file changed +18
-3
lines changed
1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -1614,11 +1614,10 @@ INSERT INTO #ManufacturingTimes VALUES
1614
1614
GO
1615
1615
1616
1616
-- Solution 1
1617
- -- MAX
1617
+ -- MAX with INNER JOIN
1618
1618
WITH cte_Max AS
1619
1619
(
1620
- SELECT ProductID,
1621
- MAX (DaysToManufacture) AS MaxDaysToManufacture
1620
+ SELECT ProductID, MAX (DaysToManufacture) AS MaxDaysToManufacture
1622
1621
FROM #ManufacturingTimes b
1623
1622
GROUP BY ProductID
1624
1623
)
@@ -1628,6 +1627,22 @@ FROM #Orders a INNER JOIN
1628
1627
GO
1629
1628
1630
1629
-- Solution 2
1630
+ -- MAX with correlated subquery
1631
+ WITH cte_Max AS
1632
+ (
1633
+ SELECT ProductID, MAX (DaysToManufacture) AS MaxDaysToManufacture
1634
+ FROM #ManufacturingTimes b
1635
+ GROUP BY ProductID
1636
+ )
1637
+ SELECT *
1638
+ FROM #Orders a
1639
+ WHERE EXISTS (SELECT *
1640
+ FROM cte_Max b
1641
+ WHERE a .ProductID = b .ProductID AND
1642
+ a .DaysToDelivery >= b .MaxDaysToManufacture );
1643
+ GO
1644
+
1645
+ -- Solution 3
1631
1646
-- ALL
1632
1647
SELECT a.*
1633
1648
FROM #Orders a
You can’t perform that action at this time.
0 commit comments