I am doing an SQL statement that tries to get the percentage..but i dont know how to do it in MySQL

here is the sample of my code:

SELECT count( * ) , rating, percentage....
FROM `acne_prod_rating`
WHERE prod_id =5
GROUP BY rating

the output should be like this:

count(*) rating percentage
7 1 70%
2 2 20%
1 3 10%

rating legend : ( this means..user rates the product)
1 = highly recommended , got 7 votes
2 = average , got 2 votes
3 = bad , got 1 vote


I know I can do it on client code, but I'd like in sql easy and faster

select votes, rating, votes/sum(votes) as percentage

if that doesn't work, then you may need to do a nested select statement, where the inner one gets the sum() first.

and whats client code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.