|
发表于 2020-5-13 17:45:02
|
显示全部楼层
create table #temp
(id varchar(50)
)
insert into #temp
select '1' union all select '2' union all select '3' union all select '4' union all select '5' union all select '6' union all select '7' union all select '8'
select * from #temp
----------------------
id
1
2
3
4
5
6
7
8
查询前后两位ID
select * from #temp
where
[id] in(select distinct top 2 [id] from #temp where [id]<5 order by [id] DESC)
or
[id]=5
or
[id] in(select distinct top 2 [id] from #temp where [id]>5 order by [id] ASC)
-------------
id
3
4
5
6
7
|
|