Page 1 of 1

PHP/MYSQL Percentage of total with rollup

Posted: Fri Feb 10, 2012 10:14 am
by cjkeane
Hi everyone,

I'm trying to get the percentage of each person who performed work, but the total percentage is never 100%. It shows up as 99%. I've been struggling with this for quite some time. Does anyone have any helpful hints which may help resolve my issue?

Code: Select all

<?PHP
$string = "SELECT COUNT(Therapist) AS Count, Round(100*COUNT(Therapist)/Count2,0) + '%' AS Percentage, Date_Of_Entry, Therapist, SUM(BILL_TIME) AS BILL_TOTAL
FROM tblprivatepracticedetails, 
     (SELECT COUNT( Therapist ) AS Count2
     FROM tblprivatepracticedetails
     ) AS c
WHERE Date_Of_Entry Between '$FromDate' And '$ToDate' GROUP BY Therapist WITH ROLLUP";
$query = mysql_query($string) or die (mysql_error());
?>

Re: PHP/MYSQL Percentage of total with rollup

Posted: Sat Feb 11, 2012 2:59 pm
by califdon
I would guess that it's just a rounding error, which is to be expected when you round to 0 digits, as you are doing. The actual result of dividing one count of therapists by the count of all the therapists might be numbers like 33.333333333 or 16.666666667 but when you round them and add them up, they are unlikely to ever total precisely 100.

Re: PHP/MYSQL Percentage of total with rollup

Posted: Sat Feb 11, 2012 4:20 pm
by cjkeane
thanks. i figured out my error. the issue is resolved.