2017-05-15 18 views
-1

私のデータベースには以下のデータがあります。時間差平均の計算方法は?

私は私がしようとしています(ServiceTime(ServiceEnd-ServiceStart)< = EstimateServiceTime)/ interactionCount

理由での相互作用のこの

するvar serviceSuccess =数などの従業員のためのサービスの成功を計算したい

EmployeeId ServiceStart ServiceEnd  EstimateSErviceTime ServiceSuccess 
1    1:00   2:30   1:00     ?% 
2    2:00   3:00   00:45 
3    3:00   3:30   00:30 
4    12:00   1:30   1:15 
5    2:00   3:00   1:30 

このようにするには:

SUM(case when AverageServiceTime < EstimateServiceTime then 1 
     else 0 
    end)/COUNT(I.Id) ServiceSuccess 
from Interaction I 

ServiceSucessを計算する方法。

+0

?それはタイプミスですか? – Tanner

+0

@Tannerはい、タイプミスで修正されました。 –

+0

期待される出力を表示できますか? –

答えて

1

あなたはかなり近づいています。 1つの問題は整数除算であり、常に0になる傾向があります。

私はこれを行うだろう:なぜ行3(社員3)は、時間に戻って行くん

select avg(case when AverageServiceTime < EstimateServiceTime then 1.0 else 0 end) as ServiceSuccess 
from Interaction I