原表:
num
0
1
1
2
5
结果:
num count
0 1
1 2
3 0
4 0
5 1
with recursive sqe(num) as
(select 1 as num
union all
select 1 + num as num
from t_sqe
where num < 5
)
select a.num,case when b.cut is not null then b.cut else 0 end as cut from sqe a
left join
(select
num,
count(num) as cut
from table1
group by num)b on a.num = b.num