2016-08-30 1 views
0

タイムスタンプで分単位でグループ化しながら合計と平均を求めるクエリがあります。ただし、タイムスタンプの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のタイムスタンプが上記のクエリでは欠落している方法に気付くことDATEPARTのでしたがって、基本的

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 

(代わりに10に等しくなければならない上記NumCardsPassed、それは10で通過午前11時13 numcardsにこれを追加しました)時間に関係なく、すべての行を同じ分数でグループ化しています。時間と日付を考慮する方法はありますか?分だけではありません。私は数分ではなく、秒またはミリ秒でグループ化するためにそれでも必要です。

答えて

0

が(笑ところで素敵な名前)これを試してみてください..以下のクエリをお試しください:

Select sum(numcardspassed) as "NumCardsPassed", sum(numcardsfailed) as "NumCardsFailed", 
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 convert(varchar, ProcessingDate, 108) 
order by processingdate 
0

しかし、タイムスタンプは、行データはこれを試して

を表示されないのと同じ分が異なる時間に..

group by 
DatePart(minute, orderprocessormetrics.processingdate), 
DatePart(hour, orderprocessormetrics.processingdate), 
DatePart(day, orderprocessormetrics.processingdate) 
0

あなたは切り捨てる必要がある場合日時を分にします。ここでは一つの方法である:

select dateadd(minute, datediff(minute, 0, processingdate), 0) as to_the_minute, 
     sum(numcardspassed) as NumCardsPassed, 
     avg(processingtime) as ProcessingTime 
From orderprocessormetrics 
where ProcessingDate >= '2016-08-27' and ProcessingDate < '2016-08-30' and 
     PreprocessorType = 'SOP' and 
     numcardsPassed > 0 and 
     clientid = 6820 
group by dateadd(minute, datediff(minute, 0, processingdate), 0) 
order by to_the_minute; 
0

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 CAST(orderprocessormetrics.processingdate as date) 
,DatePart(hour, orderprocessormetrics.processingdate) 
,DatePart(minute, orderprocessormetrics.processingdate) 
order by processingdate 
関連する問題