开发者

Complicated SQL query - how do i do it?

I'm currently working on a small feature fo开发者_如何学运维r 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 !


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


You need something like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜