I have this MySQL that I am using to calculate a percentage for a segment in a call. When a new record is added, I am able to get the correct percentage for each row.
$sumGreeting = $dbcon->prepare("
SELECT SUM(greeting_msg + provide_agent_name + clear_and_aud +
confirm_caller_name + confirm_caller_tel +
ask_alt_number) AS SumGrt
FROM table
GROUP BY coach , id
"); $sumGreeting->execute();
I want to calculate the final percentage each time a new record is added. Taking in mind the previous or existing records. At the moment I'm getting this result below:
I'm using this code:
$initRows = 0;
$result = 0;
while ($row = $sumGreeting->fetch(PDO::FETCH_ASSOC))
{
$initRows = $row['SumGrt'];
$result = ($initRows/12)*100;
echo var_dump($result);
echo $result ." <br />";
}
The Expected results will be the final percentage of all the columns.
This section has a total of 12 points.
Thanks in advance
GROUP BY
or addcoach, id
to theSELECT
list. – Rick James Jun 22 '18 at 20:06