working out percentages on the fly?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
recci
Forum Commoner
Posts: 42
Joined: Tue Jul 29, 2008 10:01 pm

working out percentages on the fly?

Post by recci »

ok im trying to calculate a percentage on the fly with mysql.

My table now looks like this :

vote_id*, voter_id, vote_date, voter_ip, votee_id, title_id.

I have the first part of the query working ok

SELECT votee_id, title_id, COUNT( vote_id )
FROM jos_comprofiler_plug_fun2
WHERE votee_id =79
GROUP BY title_id;

Nice and simple it gives me the number of votes each title has according to a specific votee:

votee_id, title_id, COUNT( vote_id )
79, 1, 1
79, 2, 1
79 , 3, 4
79 , 4, 2
79 , 5, 1
79 , 6, 1


But how do I change this query to give me the percentage of votes each title has according to a specific votee?

Iv been trying to figure it out based on the previous posts and other examples online but I just cant get it to work, Its complicated and been doing my head in. I'm guessing a subquery?
PietM
Forum Newbie
Posts: 8
Joined: Mon Oct 06, 2008 2:56 am

Re: working out percentages on the fly?

Post by PietM »

I think this CAN be done with a subquery, but I would just calculate the total number of votes first, and then use that value in the second query.
Post Reply