Skip to content

Commit bc62977

Browse files
Update Advanced SQL Puzzles Solutions.sql
1 parent f7ade1b commit bc62977

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Advanced SQL Puzzles/Advanced SQL Puzzles Solutions.sql

+14
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,20 @@ FROM cte_ValidPrices
975975
WHERE Rnk = 1;
976976
GO
977977

978+
--Solution 3
979+
--MAX
980+
WITH cte_MaxEffectiveDate AS
981+
(
982+
SELECT ProductID,
983+
MAX(EffectiveDate) AS MaxEffectiveDate
984+
FROM #ValidPrices
985+
GROUP BY ProductID
986+
)
987+
SELECT a.*
988+
FROM #ValidPrices a INNER JOIN
989+
cte_MaxEffectiveDate b on a.EffectiveDate = b.MaxEffectiveDate AND a.ProductID = b.ProductID;
990+
GO
991+
978992
/*----------------------------------------------------
979993
Answer to Puzzle #21
980994
Average Monthly Sales

0 commit comments

Comments
 (0)