所以我有一個查詢,我試圖找到總和和平均值,而按時間戳分組到分鐘。但是,如果時間戳記具有SAME分鐘但在不同的小時內,那麼行數據不會顯示。以下是我的查詢和輸出以及單獨的行:GroupBy Datepart函數缺少數據
NumCardsPassed ProcessingTime ProcessingDate
10 4 2016-08-29 11:13:44.000
1 0 2016-08-29 11:49:43.000
2 1 2016-08-29 12:19:42.000
這裏是所有分組的單獨行。請注意如何的12:13和22:13的時間戳在上面的查詢失蹤(以上NumCardsPassed應等於10,相反,它把它添加到11:13 numcards 10通過)
NumCardsPassed ProcessingTime processingdate
1 2 2016-08-29 11:13:44.000
1 0 2016-08-29 11:49:43.000
8 10 2016-08-29 12:13:44.000
1 3 2016-08-29 12:19:42.000
1 0 2016-08-29 22:13:47.000
Select sum(numcardspassed) as "NumCardsPassed",
avg(processingtime) as "ProcessingTime", min(ProcessingDate) as "ProcessingDate"
From orderprocessormetrics
where ProcessingDate >= '8/27/2016' and ProcessingDate < '8/30/2016' and PreprocessorType = 'SOP' and numcardsPassed > 0 and clientid = 6820
Group by DatePart(minute, orderprocessormetrics.processingdate)
order by processingdate
所以基本上,因爲這DATEPART以分鐘爲基礎,它將所有行分組在一起,而不管小時數。有沒有辦法考慮小時和日期,而不僅僅是分鐘。我仍然需要它按分鐘分組,而不是幾秒或幾毫秒。