Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To: Get a better average
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01447163
Message ID:
01447170
Vues:
41
I think what we want (and I didn't check any math sites yet) is to get the middle value out of 10 ordered and then only sum and count values that are within the 90% of this middle value.

E.g.

0.1

10

12

13

14

15
15

16
17
1000

In this sample, we would not count the very first and very last item.

So, first we need to get the 5th item in the ordered set and then do
sum(case when abs(Duration - @MiddleDuration)/@MiddleDuration  <= 0.1 then Duration end) as TotalDuration, 
sum(case when Duration - @MiddleDuration)/@MiddleDuration  <= 0.1 then 1 end) as CountOfCases 
from myTable group by SomeField
Average would be TotalDuration/CountOfCases

>Right now, when cases are being entered, the estimated procedure time is based on the average, or mean, of the durations of the previous 10 cases. Because averages include outlying very short as well as very long cases, this often leads to inaccurate estimates which have to be overridden by the person entering the new case. Below is the query I currently use. I'm wondering if there is a better way to calculate the average time, rather than using the straight AVG() function. One of the users of our system suggested using the 90th percentile method...but I don't really know (or couldn't find) what that would produce or be implemented. So I turn to all the math guru's here at UT and ask for your help and insight.
>
>Thanks in advance.
>Kirk
>
>
>declare @tiPerID int
>declare @tiProcID int
>set @tiPerID=1135
>set @tiProcID = 14161
>
>SELECT
>	avg(det.ortime) as AvgORMinutes
>	FROM (select top 10
>		dbo.meetings.enteror, dbo.meetings.exitor,
>		datediff(mi,enteror,exitor) as ORTime,meetproc.procid
>	      FROM   dbo.meetings (nolock) INNER JOIN
>		dbo.meetproc (nolock) ON dbo.meetings.meetingnumber = dbo.meetproc.meetingnumber
>	      WHERE  (dbo.meetproc.coperid = @tiPerID) AND (dbo.meetings.iscompleted = 1)
>		  AND  (dbo.meetproc.procid=@tiProcID)
>                  ------------------------------------------------
>                  -- Filter so we only include cases where this
>                  -- was the only procedure included on the case
>                  ------------------------------------------------
>		  AND (SELECT COUNT(*) 
>			FROM dbo.meetproc mp (nolock) 
>			WHERE dbo.meetings.meetingnumber = mp.meetingnumber
>			AND (dbo.meetproc.coperid = @tiPerID) 
>			AND  (dbo.meetproc.procid=@tiProcID)) = 1 
>	      ORDER BY endtime desc )det
>group by det.procid
>
>
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform