NutzCN Logo
问答 SQL查询数字区间里的缺省值
发布于 2460天前 作者 qq_6c5a7e9a 1615 次浏览 复制 上一个帖子 下一个帖子
标签:

假如现在有不连续的数字[1,2,3,5,6,7,8,10,11,12,15]在test表里的id字段
postfresql可以通过sql:

with recursive tb1 as(
	select min(id) as min,max(id) as max,1 as number
	from test
	union select tb1.min,tb1.max,tb1.number+1
	from tb1
	where tb1.number<tb1.max
)
select tb1.number 
from tb1
left join test as tb2 on tb2.id = tb1.number
where tb2.id is null;

查询出区间里的缺省数字
请问这个功能通过MySQL怎么书写SQL?

0 回复
添加回复
请先登陆
回到顶部