日期:2014-05-17  浏览次数:20567 次

sql语句问题,请高手解答,在线等啊!!非常急
有一张表中的一列,数据如下:
num1
3
6
7
9

我想用一句sql语句取出去除表中最小值后的数字最小值,也就是说现表中的最小数字是3,应该取出的结果是1。但是如果表中数据发生改变,
num1
1
3
5
7

那当前取出的结果应该是2。

想请问高手该如何用一句SQL语句写出,谢谢。

------解决方案--------------------
OR:
create table tb(num1 int)
insert into tb select 3 union all select 6 union all select 9
go
select top 1 rn from(select row_number()over(order by num1)rn from tb)a
where not exists(select 1 from tb where num1=a.rn)
/*
-----------
1

(1 行受影响)
*/
go
insert into tb select 1
select top 1 rn from(select row_number()over(order by num1)rn from tb)a
where not exists(select 1 from tb where num1=a.rn)
/*
-----------
2

(1 行受影响)
*/
go
drop table tb