Cosmos75
Registered User.
- Local time
 - Today, 00:41
 
- Joined
 - Apr 22, 2002
 
- Messages
 - 1,280
 
I see it now, you need the field Ranking to identify a unique Test within each HOSP-PLS pair! Am I right? 
So it Counts/Sums for Ranking = 1, then 2, then 3 till it reaches the highest ranking for the HOSP-PLS pair!! Hence the Ranking<=a.Ranking part of your SQL Statement.
But doesn't that negate the need for a calculated RunningCount? MovingAverage could just be RunningSum/Ranking.

 So it Counts/Sums for Ranking = 1, then 2, then 3 till it reaches the highest ranking for the HOSP-PLS pair!! Hence the Ranking<=a.Ranking part of your SQL Statement.
But doesn't that negate the need for a calculated RunningCount? MovingAverage could just be RunningSum/Ranking.