Loane Sharp wrote:
>Hi Ross
>This is no doubt going beyond the call of duty, but how would I calculate
>the percentile for each of, say, 1,000 records (ie. not using a single value
>assigned to the %X local variable)?
>Best regards
>Loane
>
>
>"Loane Sharp" <look_sharp_not@hotmail.com> wrote in message
>news:uKwBiBmrFHA.332@tk2msftngp13.phx.gbl...
>
>
>>thanks very much ross
>>
>>"Ross Presser" <rpresser@NOSPAMgmail.com.invalid> wrote in message
>>news:1ofx1hl32hhjz$.dlg@rosspresser.dyndns.org...
>>
>>
>>>On Tue, 30 Aug 2005 18:01:49 +0200, Loane Sharp wrote:
>>>
>>>
>>>
>>>>Hi there
>>>>I picked up Ken Henderson's book on T-SQL which has been really
>>>>enlightening
>>>>about what is possible, but a bit over my head in terms of
>>>>operationalization. However he doesn't seem to cover calculating
>>>>percentiles. Is there another useful reference, or can you point me
>>>>essentially in the right direction?
>>>>Best regards
>>>>Loane
>>>>
>>>>
>>>
http://www.sqlteam.com/item.asp?ItemID=16480 covers the subject in
>>>detail.
>>>
>>>Basically, the percentile rank of a given score X is the percent of
>>>scores
>>>in the set that are less than X. So:
>>>
>>>SELECT
>>> convert(float, SUM(case when T.Value <= @X then 1 else 0 END)) /
>>>COUNT(*)
>>>AS Percentile
>>>FROM MyTable T
>>>
>>>is the quick answer to the question. The convert(float, ) is necessary
>>>because otherwise the division would be between two integers, which would
>>>always result in zero.
>>>
>>>
>>
>>
>
>
>