之前項目中就遇到查詢所有部門層級的需求,當時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