Hello!

I have a table with basically 1 column in it that I'd like to get statistics from from time to time. The table is called query_spy and its one column is queryid:

queryid
---------
1
2
2
5
100
9
7
2
3
2

I'd like to get a report showing what percentage of the time each distinct queryid appears (in descending order) and also a percentile ranking of the number of times each queryid appears. I know how to write a query to do the first part:

select queryid, (count(*) * 100) / (select count(*) from query_spy) as pct from query_spy group by queryid order by pct desc

queryid | pct
---------------
2 | 40
1 | 10
5 | 10
100 | 10
9 | 10
7 | 10
3 | 10

but, I don't know how to basically do a running total of the pct in another column to give me a percentile (or, more appropriately, a running total of 1-pct).

Thanks for the help!
Mark