WITH base AS ( SELECt 1 N FROM DUAL UNIOn ALL SELECt 2 N FROM DUAL UNIOn ALL SELECt 3 N FROM DUAL UNIOn ALL SELECt 6 N FROM DUAL UNIOn ALL SELECt 7 N FROM DUAL UNIOn ALL SELECt 17 N FROM DUAL UNIOn ALL SELECt 18 N FROM DUAL UNIOn ALL SELECt 19 N FROM DUAL UNIOn ALL SELECt 21 N FROM DUAL), lagged AS( SELECt n, LAG(n) OVER (ORDER BY n) lag_n FROM base), groups AS( SELECt n, row_number() OVER (ORDER BY n) groupnum FROM lagged WHERe lag_n IS NULL OR lag_n < n-1), grouped AS( SELECt n, (SELECT MAX(groupnum) FROM groups WHERe groups.n <= base.n ) groupnum FROM base)SELECt groupnum, MIN(n), MAX(n) FROM grouped GROUP BY groupnum ORDER BY groupnum
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)