How to get the percentage..??

Reply

Join Date: May 2005
Posts: 5
Reputation: rsaicrag is an unknown quantity at this point 
Solved Threads: 0
rsaicrag rsaicrag is offline Offline
Newbie Poster

How to get the percentage..??

 
0
  #1
May 10th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 836
Reputation: Phaelax is on a distinguished road 
Solved Threads: 44
Phaelax Phaelax is offline Offline
Practically a Posting Shark

Re: How to get the percentage..??

 
0
  #2
May 10th, 2005
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 19273 | Replies: 1
Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC