当前位置:编程学习 > C#/ASP.NET >>

ASP.NET SQL语句问题

如果有一个ID=5

我想写一条SQL语句,取出ID=5的,前10条数据和后10条数据,包括ID=5,

共21条怎么处理??  --------------------编程问答-------------------- 有一点没说清楚 ID=5 的前10和后10条数据都是按什么顺序排列的? --------------------编程问答--------------------

(select top 10 * from (select top 10 * from dbo.TBL_USER order by ID asc)aa )
union all
(select top 10 * from TBL_USER where ID ='5')
union all
select * from 
(select top 10 * from dbo.TBL_USER order ID desc)bb
--------------------编程问答--------------------
select top 11 * from table  where id>5 order by id asc
union all
select top 10 * from table where id <5 order by id desc
--------------------编程问答--------------------

select * from [Table] where id>=cint(id)-10 and id<=cint(id)+10
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,