I have a table with 3 columns which looks like this:
File User Rating (1-5)
------------------------------
00001 1 3
00002 1 4
00003 2 2
00004 3 5
00005 4 3
00005 3 2
00006 2 3
Etc.
I want to generate a query that outputs the following (for each user and rating, display the number of files as well as percentage of files):
User Rating Count Percentage
-----------------------------------
1 1 3 .18
1 2 6 .35
1 3 8 .47
2 5 12 .75
2 3 4 .25
With Postgresql, I know how to create a query that includes the first 3 columns using the following query, but I can't figure out how to calculate percentage within the GROUP BY:
SELECT
User,
Rating,
Count(*)
FROM
Results
GROUP BY
User, Rating
ORDER BY
User, Rating
Here I want the percentage calculation to apply to each user/rating group.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…