读书人

SQL语句的有关问题

发布时间: 2012-01-09 21:05:42 作者: rapoo

求一个SQL语句的问题
怎么才能得到一个已经知道的一条数据的上面和下面的语句,不能用游标,只能用SELECT和函数结果集
谁能举个例子谢谢了

[解决办法]
这样可否

SQL code
create table tb(id int,a int,b int,c int)insert into tb values(10,2,5,1)insert into tb values(21,3,4,3)insert into tb values(29,1,2,3)insert into tb values(33,4,5,6)insert into tb values(102,7,8,9)select * from(  select top 2 * from tb where id <29 order by id desc) aunion all  select top 2 * from tb where id >29 order by id ascdrop table tb/*id          a           b           c           ----------- ----------- ----------- ----------- 10          2           5           121          3           4           333          4           5           6102         7           8           9*/ 

读书人网 >SQL Server

热点推荐