File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 811811INSERT INTO #SeatingChart VALUES (0 );
812812GO
813813
814+ -- -----------------
814815-- Gap start and gap end
815816WITH cte_Gaps AS
816817(
@@ -825,8 +826,10 @@ FROM cte_Gaps
825826WHERE Gap > 1 ;
826827GO
827828
829+ -- -----------------
828830-- Missing Numbers
829- WITH cte_Rank
831+ -- Solution 1
832+ -- This solution provideds a method if you need to window/partitition the recordsWITH cte_Rank
830833AS
831834(
832835SELECT SeatNumber,
@@ -838,6 +841,13 @@ WHERE SeatNumber > 0
838841SELECT MAX (Rnk) AS MissingNumbers FROM cte_Rank;
839842GO
840843
844+ -- Solution 2
845+ SELECT MAX (SeatNumber) - COUNT (SeatNumber) AS MissingNumbers
846+ FROM #SeatingChart
847+ WHERE SeatNumber <> 0 ;
848+ GO
849+
850+ -- -----------------
841851-- Odd and even number count
842852SELECT (CASE SeatNumber%2 WHEN 1 THEN ' Odd' WHEN 0 THEN ' Even' END ) AS Modulus,
843853 COUNT (* ) AS [Count]
You can’t perform that action at this time.
0 commit comments