create table yw(ID int)insert into yw(ID) select 1 union all select 6 union all select 8 union all select 4 select a.number 'ID' from (select number from master.dbo.spt_values where type='P' and number between 1 and (select max(ID) from yw)) a left join yw b on a.number=b.ID where b.ID is null/* ID ----------- 2 3 5 7(4 row(s) affected) */
-- 凑个热门 drop table seq go select identity(int,1,1) rn into seq from sysobjects go select top 1 rn from (select ROW_NUMBER()over(order by name) rn from master..syscolumns) as t where t.rn not in (select rn from seq) order by 1
create table yw(ID int)insert into yw(ID)
select 1 union all
select 6 union all
select 8 union all
select 4
select a.number 'ID'
from
(select number
from master.dbo.spt_values
where type='P' and number between 1 and (select max(ID) from yw)) a
left join yw b on a.number=b.ID
where b.ID is null/*
ID
-----------
2
3
5
7(4 row(s) affected)
*/
-- 凑个热门
drop table seq
go
select identity(int,1,1) rn into seq from sysobjects
go
select top 1 rn from
(select ROW_NUMBER()over(order by name) rn from master..syscolumns) as t
where t.rn not in (select rn from seq)
order by 1
怎么扯上了master表,type='P'是啥意思,这个不具有通用性,mysql里能用吗
大概看明白意思,找出最大的值,然后在1和最大值间找不在表中的值
mysql是怎么写?