1

表如下所示:

create table #rankme (rankmeid int identity(1000, 1) primary key, 
                      step int null, checkvalue int null)

insert into #rankme values ( 10 , 1 )
insert into #rankme values ( 15 , null )
insert into #rankme values ( 20 , null )
insert into #rankme values ( 40 , null )

select * from #rankme order by step,checkvalue

作为step一个参数,我试图找出在我请求checkvalue之前的step请求是否为空。

所以我想选择where step=20并得到NULL.

我想选择where step=15并获得一个1.

我试图想出一些基于“rank-1”的东西,但到目前为止还没有雪茄。

帮助?

4

1 回答 1

2
declare @step int = 15

select top(1) R.checkvalue
from #rankme as R
where R.step < @step
order by R.step desc
于 2011-10-30T08:17:44.360 回答