Retrieve names by ratio of their occurance
Posted
by jjiffer
on Stack Overflow
See other posts from Stack Overflow
or by jjiffer
Published on 2010-06-15T18:08:27Z
Indexed on
2010/06/15
18:12 UTC
Read the original article
Hit count: 297
sql
Hello,
I'm somewhat new to SQL queries, and I'm struggling with this particular problem.
Let's say I have query that returns the following 3 records (kept to one column for simplicity):
Tom
Jack
Tom
And I want to have those results grouped by the name and also include the fraction (ratio) of the occurrence of that name out of the total records returned.
So, the desired result would be (as two columns):
Tom | 2/3
Jack | 1/3
How would I go about it? Determining the numerator is pretty easy (I can just use COUNT() and GROUP BY name), but I'm having trouble translating that into a ratio out of the total rows returned.
Any help is much appreciated!
© Stack Overflow or respective owner