在前作 https://www.cnblogs.com/xiandedanteng/p/12735898.html中,我们可以用Java程序制成三角序列.
1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6, 7,7,7,7,7,7,7, 8,8,8,8,8,8,8,8, 9,9,9,9,9,9,9,9,9,
其实在SQL里也能做到,程序如下:
select level,floor(sqrt(2*level)+1/2) from dual connect by level<22;
结果如下:
这种做法的核心是通项公式 f(n)=floor(sqrt(2n)+0.5)
然后利用分析函数来做三角序列就可以了:
select listagg(n,',') within group( order by n) from ( select floor(sqrt(2*level)+1/2) as n from dual connect by level<46 ) group by n
结果:
--2020-04-23--