例如你的字段名为 xid,表名为 x_eng 那么:select top 1 xid from x_eng ORDER BY xid ASC
--最小的一行 select top 1 xid from x_eng ORDER BY xid ASC --最小的10行 select top 10 xid from x_eng ORDER BY xid ASC
SELECT TOP 1 ID+1 FROM x_eng AS aaa WHERE aaa.ID=(select count(*)+1 from x_eng where aaa.ID>ID) ORDER BY aaa.ID DESC
如果要全部显示:SELECT ID+1 FROM x_eng AS aaa WHERE aaa.ID=(select count(*)+1 from x_eng where aaa.ID>ID) ORDER BY aaa.ID DESC
select min(c.b) from (select 1 as b,count(*) as a from 表名 where 字段=1 union all select 2 as b,count(*) as a from 表名 where 字段=2 union all select 3 as b,count(*) as a from 表名 where 字段=3 union all select 4 as b,count(*) as a from 表名 where 字段=4 union all select 5 as b,count(*) as a from 表名 where 字段=5 ) as c where c.a=0
--测试环境 CREATE TABLE x_eng(id int)INSERT x_eng([id]) select 1 UNION ALL select 2 UNION ALL select 5SELECT TOP 1 ID+1 FROM x_eng AS aaa WHERE aaa.ID=(select count(*)+1 from x_eng where aaa.ID>ID) ORDER BY aaa.ID DESC--结果 3
SQL Server中执行通过:create table tab(XH int) insert into tab values(2) insert into tab values(3) insert into tab values(5)select * from tabselect top 1 NewXH from (select XH,(select count(*)+1 from tab as Y where Y.XH<X.XH) as NewXH from tab as X) as ABC where XH <> NewXH order by XH drop table tab
select min(id+1) kk from tb where id+1 not in (select * from tb)
declare @tb table(id int) insert @tb select 1 union all select 2 union all select 3 union all select 4 union all select 7 union all select 9 select min(id+1) kk from @tb where id+1 not in (select * from @tb)/*结果kk ----------- 5(所影响的行数为 1 行) */
--最小的一行
select top 1 xid from x_eng ORDER BY xid ASC
--最小的10行
select top 10 xid from x_eng ORDER BY xid ASC
SELECT TOP 1 ID+1
FROM x_eng AS aaa
WHERE aaa.ID=(select count(*)+1 from x_eng where aaa.ID>ID)
ORDER BY aaa.ID DESC
FROM x_eng AS aaa
WHERE aaa.ID=(select count(*)+1 from x_eng where aaa.ID>ID)
ORDER BY aaa.ID DESC
(select 1 as b,count(*) as a from 表名 where 字段=1 union all
select 2 as b,count(*) as a from 表名 where 字段=2 union all
select 3 as b,count(*) as a from 表名 where 字段=3 union all
select 4 as b,count(*) as a from 表名 where 字段=4 union all
select 5 as b,count(*) as a from 表名 where 字段=5 ) as c
where c.a=0
--测试环境
CREATE TABLE x_eng(id int)INSERT x_eng([id]) select 1
UNION ALL select 2
UNION ALL select 5SELECT TOP 1 ID+1
FROM x_eng AS aaa
WHERE aaa.ID=(select count(*)+1 from x_eng where aaa.ID>ID)
ORDER BY aaa.ID DESC--结果
3
insert into tab values(2)
insert into tab values(3)
insert into tab values(5)select * from tabselect top 1 NewXH from
(select XH,(select count(*)+1 from tab as Y where Y.XH<X.XH) as NewXH
from tab as X) as ABC
where XH <> NewXH
order by XH drop table tab
select min(id+1) kk from tb where id+1 not in (select * from tb)
insert @tb
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 7 union all
select 9
select min(id+1) kk from @tb where id+1 not in (select * from @tb)/*结果kk
-----------
5(所影响的行数为 1 行)
*/