Skip to content

1285. Find the Start and End Number of Continuous Ranges 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
WITH
  LogToRowNumber AS (
    SELECT
      log_id,
      ROW_NUMBER() OVER(ORDER BY log_id) AS `row_number`
    FROM Logs
  )
SELECT
  MIN(log_id) AS start_id,
  MAX(log_id) AS end_id
FROM LogToRowNumber
GROUP BY log_id - `row_number`;