[英]Select Row for every 15 minutes in sql
DataType
SamplingTime : Datetime
Value : Integer
SamplingTime Value
2020-06-08 00:03:58.000 , 1.00
2020-06-08 00:03:59.000 , 5.00
2020-06-08 00:02:00.000 , 3.00
2020-06-08 00:01:58.000 , 1.00
2020-06-08 00:01:44.000 , 6.00
2020-06-08 00:01:20.000 , 2.00
I want Output to get ROW in interval of 15 minutes filter in data should give我希望 Output 以 15 分钟的间隔获取 ROW 数据过滤器应该给出
Sample Output样品 Output
2020-06-08 00:03:58.000 , 1.00
2020-06-08 00:02:00.000 , 3.00
2020-06-08 00:01:44.000 , 6.00
2020-06-08 00:01:20.000 , 2.00
Query which i tried for it:我尝试过的查询:
select dateadd(MINUTE,datediff(MINUTE,-15,SamplingTime),15), value
from RN_QOS_DATA_0001
This rowset contain info for dataSet:此行集包含数据集的信息:
Are you looking for the earliest row within each fifteen-minute division of the clock?您是否正在寻找时钟每 15 分钟刻度内的最早行?
with data as (
select *,
row_number() over (partition by dateadd(second, -1 * (
/* how many seconds into 15-minute window */
60 * datepart(minute, SamplingTime) % 15
+ datepart(second, SamplingTime)
), SamplingTime)
order by SamplingTime
) as rn
from T
)
select * from data where rn = 1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.