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://files-cdn.cnblogs.com/files/jiangyan219/Alipay.bmp)
您的资助是我最大的动力!
金额随意,欢迎来赏!
![](https://files-cdn.cnblogs.com/files/jiangyan219/WeChat.bmp)
我写的东西能让你能懂,那是义务
毕竟占用了你生命中的宝贵的时间和注意力
要是你还能喜欢我的作品,那就是缘分了
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的因为,我的写作热情也离不开您的肯定支持,感谢您的阅读,我是【青青子衿】!