SQL 查询一天中 每隔5分钟的数据 的sql语句


 1 declare @flag1 varchar(32) set @flag1='c115:'
 2 declare @flag2 varchar(32) set @flag2='c116:'
 3 select   SampleTime ,  
 4 replace ( substring ( SampleValues , charindex ( ''+@flag1+'' , SampleValues ) , charindex ( ',', substring ( SampleValues , charindex ( ''+@flag1+'' , SampleValues ) , len ( SampleValues ) ) ) - 1 ) ,''+@flag1+'' , '')   
 5 as YcValue1  ,
 6 replace ( substring ( SampleValues , charindex ( ''+@flag2+'' , SampleValues ) , charindex ( ',', substring ( SampleValues , charindex ( ''+@flag2+'' , SampleValues ) , len ( SampleValues ) ) ) - 1 ) ,''+@flag2+'' , '')   
 7 as YcValue2
 8 from [SHDQ_MGM1000_TEST].[dbo].[TYcHistory_201707]    
 9 where 1=1 
10 and ( charindex (''+@flag1+'' , SampleValues ) > 0 or charindex (''+@flag2+'' , SampleValues ) > 0 ) 
11 and  DateName(minute,SampleTime)%5=0  //时间间隔就是5分钟
12 and  datediff(day,SampleTime,'2017/7/06 0:00:00')=0 // 取时间段为这一天的数据

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM