通过构造一个指定每个批次开始的新列,以固定批次为每一刻钟进行批处理:
SELECT
*,
CASE
WHEN (DATEPART(minute, [Date]) >= 0 AND DATEPART(minute, [Date]) < 15) THEN DATETIMEFROMPARTS (DATEPART(year, [Date]), DATEPART(month, [Date]), DATEPART(day, [Date]), DATEPART(hour, [Date]), 0, 0, 0)
WHEN (DATEPART(minute, [Date]) >= 15 AND DATEPART(minute, [Date]) < 30) THEN DATETIMEFROMPARTS (DATEPART(year, [Date]), DATEPART(month, [Date]), DATEPART(day, [Date]), DATEPART(hour, [Date]), 15, 0, 0)
WHEN (DATEPART(minute, [Date]) >= 30 AND DATEPART(minute, [Date]) < 45) THEN DATETIMEFROMPARTS (DATEPART(year, [Date]), DATEPART(month, [Date]), DATEPART(day, [Date]), DATEPART(hour, [Date]), 30, 0, 0)
ELSE DATETIMEFROMPARTS (DATEPART(year, [Date]), DATEPART(month, [Date]), DATEPART(day, [Date]), DATEPART(hour, [Date]), 45, 0, 0)
END AS BatchStart
FROM
Fact
ORDER BY
[Date]
您的示例的结果:
ID key Date Value BatchStart
1 1 2013-10-08 00:00:00.000 10 2013-10-08 00:00:00.000
2 1 2013-10-08 00:23:00.000 15 2013-10-08 00:15:00.000
3 1 2013-10-08 01:00:00.000 20 2013-10-08 01:00:00.000
4 1 2013-10-08 01:15:00.000 25 2013-10-08 01:15:00.000
5 1 2013-10-08 01:30:00.000 30 2013-10-08 01:30:00.000
6 1 2013-10-08 01:35:00.000 30 2013-10-08 01:30:00.000
7 1 2013-10-08 01:50:00.000 30 2013-10-08 01:45:00.000
8 1 2013-10-08 01:55:00.000 30 2013-10-08 01:45:00.000