Page 1 of 1

working out percentages on the fly?

Posted: Fri Oct 03, 2008 10:05 am
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?

Re: working out percentages on the fly?

Posted: Mon Oct 06, 2008 7:19 am
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.