Skip to content

Commit 02abfa2

Browse files
Update Advanced SQL Puzzles Solutions.sql
1 parent 1715060 commit 02abfa2

1 file changed

Lines changed: 6 additions & 23 deletions

File tree

Advanced SQL Puzzles/Advanced SQL Puzzles Solutions.sql

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,30 +3304,13 @@ INSERT INTO #Products (Product, ProductCode) VALUES
33043304
('Alpha','01'),
33053305
('Alpha','02'),
33063306
('Bravo','03'),
3307-
('Bravo','04'),
3308-
('Charlie','02'),
3309-
('Delta','01'),
3310-
('Echo','EE'),
3311-
('Foxtrot','EE'),
3312-
('Gulf','GG');
3307+
('Charlie','02');
33133308
GO
33143309

3315-
WITH cte_Duplicates AS
3316-
(
3317-
SELECT Product
3310+
SELECT ProductCode
33183311
FROM #Products
3319-
GROUP BY Product
3320-
HAVING COUNT(*) >= 2
3321-
),
3322-
cte_ProductCodes AS
3323-
(
3324-
SELECT ProductCode
3325-
FROM #Products
3326-
WHERE Product IN (SELECT Product FROM cte_Duplicates)
3327-
)
3328-
SELECT DISTINCT ProductCode
3329-
FROM #Products
3330-
WHERE ProductCode NOT IN (SELECT ProductCode FROM cte_ProductCodes);
3312+
GROUP BY ProductCode
3313+
HAVING COUNT(DISTINCT Product) = 1;
33313314
GO
33323315

33333316
/*----------------------------------------------------
@@ -3361,8 +3344,7 @@ SELECT *
33613344
,CASE WHEN Score - LAG(Score,1,0) OVER (PARTITION BY PlayerID ORDER BY AttemptID) > 0 THEN 1 ELSE 0 END AS IsImproved
33623345
FROM #PlayerScores
33633346
)
3364-
SELECT
3365-
AttemptID
3347+
SELECT AttemptID
33663348
,PlayerID
33673349
,Score
33683350
,Score - FirstValue AS Difference_First
@@ -4210,3 +4192,4 @@ The End
42104192

42114193

42124194

4195+

0 commit comments

Comments
 (0)