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 811
811
INSERT INTO #SeatingChart VALUES (0 );
812
812
GO
813
813
814
+ -- -----------------
814
815
-- Gap start and gap end
815
816
WITH cte_Gaps AS
816
817
(
@@ -825,8 +826,10 @@ FROM cte_Gaps
825
826
WHERE Gap > 1 ;
826
827
GO
827
828
829
+ -- -----------------
828
830
-- 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
830
833
AS
831
834
(
832
835
SELECT SeatNumber,
@@ -838,6 +841,13 @@ WHERE SeatNumber > 0
838
841
SELECT MAX (Rnk) AS MissingNumbers FROM cte_Rank;
839
842
GO
840
843
844
+ -- Solution 2
845
+ SELECT MAX (SeatNumber) - COUNT (SeatNumber) AS MissingNumbers
846
+ FROM #SeatingChart
847
+ WHERE SeatNumber <> 0 ;
848
+ GO
849
+
850
+ -- -----------------
841
851
-- Odd and even number count
842
852
SELECT (CASE SeatNumber%2 WHEN 1 THEN ' Odd' WHEN 0 THEN ' Even' END ) AS Modulus,
843
853
COUNT (* ) AS [Count]
You can’t perform that action at this time.
0 commit comments