tags:

views:

174

answers:

2

Hey Everyone

I'm currently working on a small feature for a project and wondered how best to achieve the result, i have a table full of reviews with the score being out of 5 and being stored as score in the database, on one page i want to show how many of each score reviews there are, ie number of 5 star reviews, 4 star etc

But i don't know how best to achieve surely i don't need 5 different queries, that would be awful design would it not ?

Thanks and hope you can help !

+9  A: 

Since I do not have your table structure, I would do something similar to this (with appropriate names replaced)

edited SQL based on comments

Select Score, COUNT (*) as NumScores
From MyTableOfScores
Group By Score
Order by Score Desc
Raj More
Maybe you would like `Order by Score DESC`
True Soft
worked perfectly - thanks very very much - couldn't have done it without you :)
David
+3  A: 

You need something like this:

select score, count(*) from reviews group by score
jamesaharvey