日期:2014-05-16  浏览次数:20596 次

如何查询记录中数值在某个范围内的那个点的记录?
表是个流水的记录,假设每5秒记录一次当前的温度 ,如下:

TimePoint                    TempValue    PF
20131201080100       20.02              0.2      
20131201080105       27.33              1.2 
20131201080110       31.36              1.4
20131201080115       32.00              1.8
20131201080120       28.59              0.2 
20131201080125       50.26              1.4
20131201080130       20.34              1.6
20131201080135       40.18              1.5
20131201080140       35.00              1.0  
20131201080145       20.21              0.2
20131201080150       20.54              0.2
20131201080155       31.22              0.9 

得到数据  
20131201080100       20.02   关
20131201080110       31.36   开
20131201080120       28.59   关
20131201080135       40.18   开
20131201080145       20.21   关 

中间隔多少条记录不一定,就是要看那个临界的记录,根据 后面两个列进行判断,
TempValue 在 30.00-40.00 之间 并且 PF 在 1.0-2.0之间 

这种查询,因个人水平问题,除了循环判断,没有太好的想法,求大神指点。

------解决方案--------------------
引用:
测试数据奉上 


with tb(TimePoint,TempValue,PF)as(
select 20131201080100,20.02,0.2 union 
select 20131201080105,27.33,1.2 union
select 20131201080110,31.36,1.4union
select 20131201080115,32.00,1.8union
select 20131201080120,28.59,0.2 union
select 20131201080125,50.26,1.4union
select 20131201080130,20.34,1.6union
select 20131201080135,40.18,1.5union
select 20131201080140,35.00,1.0  union
select 20131201080145,20.21,0.2union
select 20131201080150,20.54,0.2union
select 20131201080155,31.22,0.9 )
select * from tb

楼主的  20131201080135       40.18   开  这条是开, 为什么 20131201080125       50.26         &