日期:2014-05-17  浏览次数:20434 次

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
    )