KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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.
Tags (comma-separated)
Save Edits
Cancel