27,579
社区成员
发帖
与我相关
我的任务
分享
;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)
declare @table table
(
id int
)
insert into @table(id)
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 6 union all
select 8 union all
select 9 union all
select 10 union all
select 11 union all
select 13 union all
select 14 union all
select 15 union all
select 17 union all
select 18
--查出缺少的数字
select number from master.dbo.spt_values where type='p' and number!=0 and number<=(select max(id) from @table) and number not in(select id from @table)
select a.number 'qzh'
from master.dbo.spt_values a
left join (select qzh from [表名] group by qzh) b
on a.type='P' and a.number>0 and a.number=b.qzh
where b.qzh is null