Finding Percentiles

pickslides

Red Sails In The Sunset
Local time
Tomorrow, 02:34
Joined
Apr 29, 2008
Messages
76
Hi guys, i am writing a simple query grouping some parameters to find a number of calculations.

The 2 i am having trouble with are the median and 90th percentile of my data.

I'm sure the median will be easy enough and i'll kick myself once i know.
 
here are some hints:

for finding the median of a numeric data type field:
Code:
SELECT max(field) AS MEDIAN
  FROM table
    WHERE [field] IN 
      (SELECT TOP 50 PERCENT [field] FROM table ORDER BY [field] ASC);
for finding the 90th percentile:
Code:
SELECT max(field) AS 90th
  FROM table
    WHERE [field] 
      IN (SELECT TOP 90 PERCENT [field] FROM table ORDER BY [field] ASC);
 
Dang, I wish I would have had that solution in Oracle 8 years ago.
 
I'm still at a bit of a loss as my SQL skills are zero, I have simply cut and paste these commands (Thanks Adam!) into the SQL view of my query, after this i try to save or exit and it spits some tricky jargon at me!

Ultimately i would like to group by a certain parameter to find the median of each.

I.e Table: "Daily Outlet"

Parameter Result
--------------------
Na 3
Na 4
S 1
S 1
Si 0
S 2
Na 5
Si 4

So my Query will return


Parameter Median
-------------------
Na 4
S 1
Si 2
 
this is virtually impossible to do with the built-in query wizard.

If you want a list of medians from a user chosen value or values, I would simply use some form controls to populate these lists. That way, you have the full capacity of VBA in your toolbox, because you will most likely need it for something like this...
 

Users who are viewing this thread

Back
Top Bottom