我有一个表,主键(bigint),日期时间,值,foreignKey到配置表,包含100,000行.我希望能够获得一个可变时间间隔的行.例如.
Select Timestamp, value from myTable where configID=3
AND{most recent for 15 min interval}
Run Code Online (Sandbox Code Playgroud)
我有一个CTE查询,它返回间隔时间间隔的多行
WITH Time_Interval(timestamp, value, minutes)
AS
(
Select timestamp, value, DatePart(Minute, Timestamp) from myTable
Where Timestamp >= '12/01/2012' and Timestamp <= 'Jan 10, 2013' and
ConfigID = 435 and (DatePart(Minute, Timestamp) % 15) = 0
)
Select Timestamp, value, minutes from Time_Interval
group by minutes, value, timestamp
order by Timestamp
Run Code Online (Sandbox Code Playgroud)
如:
2012-12-19 18:15:22.040 6.98 15
2012-12-19 18:15:29.887 6.98 15
2012-12-19 18:15:33.480 7.02 15
2012-12-19 18:15:49.370 7.01 …Run Code Online (Sandbox Code Playgroud)