这里面的字段值是可重复的(上面是用分组查询出的没重复的结果),但是没有连续,我想找到缺少了哪些数字,用纯sql实现的,函数的已经有了,谢谢各位了
SQL sqlserver 连续 数字连续 sql语句
------解决方案--------------------
;with t as
(
select 1 id
union all select 2
union all select 3
union all select 4
union all select 5
union all select 6
union all select 9
union all select 11
union all select 12
)
select a.number
from master..spt_values a
left join t on a.number=t.id
where a.type='p' and t.id is null
and a.number between (select min(id) from t) and (select max(id) from t)