Oracle-将行中的值转换为范围

Oracle-将行中的值转换为范围,第1张

Oracle-将行中的值转换为范围

我觉得可能可以对此进行改进,但是它可以起作用

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5649778.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存