数据库五分钟一条的数据,现根据输入不同的时间进行不同间隔的查询
程序员文章站
2024-03-15 18:15:48
...
第一:SQL With As 用法:
https://www.cnblogs.com/Niko12230/p/5945133.html
第二:Sqlserver获取行号:
select row_number() over(order by Time) as row_number,* from Record where DevSerialNumber=10000
第三:row_number% {3} = 0
根据行号进行查询,若隔十分钟查询一个,{3}占位符等于2;
若隔十五分钟查询一个,{3}占位符等于3;
{3}的算法:间隔分钟数/5(数据库每条数据间隔时间)
第四:SQL server具体代码实现,可根据自己要求更改{3}
with t_rowtable
as
(
select row_number() over(order by Time) as row_number,* from Record where DevSerialNumber='10008'
)
select *
from t_rowtable
where row_number% {3} = 0
and Time between '2018/8/17 10:53:23' and '2018/9/10 17:14:28'