取上下限值 思路

----将数据从小到大取出
select value from HistoryData hisdata0_ where 1=1 and hisdata0_.devId=112
and hisdata0_.enname='pressure' and (hisdata0_.startTime between '2017-01-01 00:00:00' and '2017-04-05 00:00:00')  --原始数据的时间范围
and isnumeric(hisdata0_.value)=1 and (cast(hisdata0_.value as float) between 0 and 1)           --数据过滤
and (cast(datepart(hour, hisdata0_.startTime) as varchar(255))+':'+cast(datepart(minute,
hisdata0_.startTime) as varchar(255)))='0:15'  --时间匹配

order by Cast(value as float) asc            从小到大排序

----根据上下限比率算出上下限位置

upperNo =(int)( allNum * upperLimitRate );   //allNum为总数据记录条数,
lowerNo=(int)( allNum * lowerLimitRate );      

 

-- 取最大值,最小值

query2.setFirstResult(upperNo);
query2.setMaxResults(1);
max = query2.list();

query2.setFirstResult(lowerNo);
query2.setMaxResults(1);
min = query2.list();

posted on 2017-06-21 19:44  lui  阅读(224)  评论(0编辑  收藏  举报