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 // 取时间段为这一天的数据

 

转载于:https://www.cnblogs.com/jiangyan219/articles/7285235.html

你可能感兴趣的:(SQL 查询一天中 每隔5分钟的数据 的sql语句)