1、 生成连续整数序列MySQL8: with recursive t(n) as (select 1union allselect n+1 from t where n<7)select * from t;Oracle:select level nfrom dual connect by level<=7;集算器 SPL:A1:构造从 1 到 7 的整数序列示例 1:百鸡问题,鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、母、雏各几MySQL8: with recursive jg(n) as (select 1 union all select n+1 from jg where n<100/5),jm(n) as (select 1 union all select n+1 from jm where n<100/3),jc(n) as (select 3 union all select n+3 from jc where n<98)select jg.n jw, jm.n jm, jc.n jcfrom jg cross join jm cross join jcwhere jg.n5+jm.n3+jc.n/3=100 and jg.n+jm.n+jc.n=100集算器 SPL:A1:构造1到20的整数序列A2:构造1到33的整数序列A3:构造1到99且步长为3的整数序列A4:创建数据结构为(jw,jm,jc)的序表A5:对A1、A2、A3的数据进行嵌套循环,若满足于A1成员+A2成员+A3成员==100且A1成员5+A2成员3+A3成员/3==100则追加到A4序表中示例2:将指定列中冒号分隔的串划分成多行Oracle:with t(k,f) as (select 1 , ‘a1:a2:a3’ from dualunion all select 2, ‘b1:b2’ from dual),t1 as (select k,f, length(f)-length(replace(f,’:’,’’))+1 cnt from t),t2 as (select level n from dual connect by level<=(select max(cnt) from t1)),t3 as (select t1.k, t1.f, n, cnt,case when n=1 then 1 else instr(f,’:’,1,n-1)+1 end p1, case when n=cnt then length(f)+1 else instr(f,’:’,1,n) end p2from t1 join t2 on t2.n<=t1.cnt)select k,substr(f,p1,p2-p1) f from t3 order by k;集算器 SPL:A1:创建数据结构为(k,f)的序表,并追加2条记录(1, “a1:a2:a3)和(2,”b1:b2”)A2:将A1的字段f用冒号划分成序列并重新赋值给字段fA3:针对A1每条记录构造数据结构为(k,f)的序表,并根据字段f中成员构造记录(A1.k,f成员)追加到此序表中2、 生成连续日期序列MySQL8:with recursivet(d) as (select date'2018-10-03’union allselect d+1 from t where d<date'2018-10-09’)select d,dayofweek(d) w from t;集算器 SPL:A1:生成2018-10-03到2018-10-09的日期序列示例:列出2015-01-03到2015-01-07每天的销量汇总MySQL8:with recursivet(d,v) as (select date'2015-01-04’,30union all select date'2015-01-06’,50union all select date'2015-01-07’,50union all select date'2015-01-03’,40union all select date'2015-01-04’, 80),s(d) as (select date'2015-01-03’union allselect d+1 from s where d<date'2015-01-07’)select s.d, sum(t.v) vfrom s left join t on s.d=t.dgroup by s.d;集算器 SPL:A4:A2中记录按字段d的值对齐到A3A5:根据A4和A3对位构造统计后的序表3、 生成连续的工作日(不包含周六周日)序列MySQL8:with recursivet(d) as (select date'2018-10-03’union allselect d+1 from t where d<date'2018-10-09’)select d,dayofweek(d) w from twhere dayofweek(d)<=5;集算器 SPL:A1:构造从2018-10-03到2018-10-09不包含周六周日的日期序列A2:根据A1构造日期及相应周几的序表4、 根据序列生成表MySQL8:with recursive t1(n) as (select 1 union all select n+1 from t1 where n<14),t2(n, name) as (select n, concat(‘a’,n) name from t1)select max(if(n%4=1, name, null)) f1,max(if(n%4=2, name, null)) f2,max(if(n%4=3, name, null)) f3,max(if(n%4=0, name, null)) f4from t2group by floor((n+3)/4);集算器 SPL: