언어 꿀Tip/SQL
10_04. 연속적인 log_id에 대한 시작, 끝 log_id 구해라 (Find the Start and End Number of Continuous Ranges)
늉이늉이
2021. 6. 30. 20:03
Since some IDs have been removed from Logs. Write an SQL query to find the start and end number of continuous ranges in table Logs.
Order the result table by start_id.
The query result format is in the following example:
select min(log_id) as start_id
,max(log_id) as end_id
from (
select log_id
,row_number()over(order by log_id) as log_no
from logs
) a1
group by log_id-log_no
;