赞
踩
先看实先效果
演示的为db2数据库,需要含有窗口函数,或者可以获取到当前数据偏移的上一位数据
WITH nums(num_no) AS ( VALUES 1,11,19,29,39,47,57,66,74,83,92,101,110,119,129,137,145,154 ),result1 as( SELECT num_no, nvl(lag(num_no, 1) OVER (ORDER BY num_no),num_no) AS next_num_no FROM nums ),result2 as ( select num_no, -- 如果相减小于10标记0 ,想法大于等于10或者等于0就标记1 (case when (num_no - next_num_no) >= 10 or (num_no - next_num_no) = 0 then 1 else 0 end) as B from result1 ),result4 as ( select *,(select sum(B) from result2 where num_no<=t1.num_no) as C from result2 t1 ) select C, LISTAGG(num_no,';'),count(C) from result4 group by C having count(C)>1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。