MySQL Forums
Forum List  »  Newbie

Percentage of values over all rows using distinct
Posted by: Niklas S
Date: July 10, 2012 10:42AM

I have one table that looks like this:

id.....category.....value
1......cool...........10
2......ok.............50
3......bad...........30
4......cool...........20

I want to select all categories and display how often they occur.
So the results should look like:

cool.....50%
ok.......25%
bad.....25%

I got this far:
SELECT distinct category, COUNT("current_category")/COUNT(id) FROM table

Any hints? :)



Edited 5 time(s). Last edit at 07/10/2012 10:53AM by Niklas S.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.