当前位置: 代码迷 >> Sql Server >> MSSQl如何查询一个字段的中间序列,比如去掉这个字段排序后的前后5%
  详细解决方案

MSSQl如何查询一个字段的中间序列,比如去掉这个字段排序后的前后5%

热度:66   发布时间:2016-04-24 21:01:26.0
MSSQl怎么查询一个字段的中间序列,比如去掉这个字段排序后的前后5%
MSSQl怎么查询一个字段的中间序列,比如去掉这个字段排序后的前后5%

------解决方案--------------------
本帖最后由 htl258 于 2013-07-28 10:11:34 编辑
;with t as
(
select top 5  percent pxid
from tb 
order by pxid 
union all
select top 5 percent pxid
from tb 
order by pxid desc
)
select * 
from tb a
where not exists(
select 1 
from t 
where pxid=a.pxid
)

--SQL2000
select * 
from tb 
where pxid not in(
select top 5  percent pxid
from tb 
order by pxid 
union all
select top 5 percent pxid
from tb 
order by pxid desc
    )

  相关解决方案