943,925 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 23964
  • MySQL RSS
May 10th, 2005
0

How to get the percentage..??

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rsaicrag is offline Offline
5 posts
since May 2005
May 11th, 2005
0

Re: How to get the percentage..??

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?
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: secure access to customer portal page?
Next Thread in MySQL Forum Timeline: Problem writing to DB can someone take a look at my query string??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC