之前项目中就遇到查询所有部门层级的需求,当时MySQL用的5.7的版本,然后我是自定义了一个函数实现了,当然,函数里面实际也是递归查询。
2021-01-29
with recursive fb_list(n1, n2) as
(
select 0, 1
union all
select n2, n1+n2 from fb_list where n1 + n2 <=100
)
select 0
union all
select n2 from fb_list;
(
select 0, 1
union all
select n2, n1+n2 from fb_list where n1 + n2 <=100
)
select 0
union all
select n2 from fb_list;
2019-11-05