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