Puzzle 18 Seating Chart #13
              
  
  Closed
              
          
                  
                    
                      maximilian22x
                    
                  
                
                  started this conversation in
                General
              
            Replies: 2 comments
-
| Thank you, I will check out this syntax. This puzzle was originally in Joe Celko's SQL Puzzle and Answer book, which is where I learned how to solve this puzzle. Thank you for letting me know of all the small errors in the puzzles. Really appreciate it. Please keep them coming. | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
| Closing | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
AdvancedSQLPuzzles/Advanced SQL Puzzles/Advanced SQL Puzzles Solutions.sql
Line 828 in 66533d0
** Also possible, but your version is better.**
WITH cte_Gaps AS
(
SELECT SeatNumber AS GapStart,
LEAD(SeatNumber,1,0) OVER (ORDER BY SeatNumber) AS GapEnd,
LEAD(SeatNumber,1,0) OVER (ORDER BY SeatNumber) - SeatNumber AS Gap
FROM #SeatingChart
)
SELECT sum((GapEnd - 1 ) - (GapStart + 1 ) + 1)
FROM cte_Gaps
WHERE Gap > 1;
GO
Beta Was this translation helpful? Give feedback.
All reactions