2016-10-04 129 views
0

我想计算平均运行时间totalscore/totalevaluatedcalls这是100.how我可以做到这一点与PHP ...和表后这里是我的代码。任何人都可以帮助我这方面,总计评估的调用是来自db的emp id的计数。如何获得php的平均分数

empid agentname totalevaluatedcalls  totalscore  avaragescore 
========================================================================= 
1  xyz   2      200    100 


total evaluatedcalls query 
========================== 

foreach($dbh->query("SELECT COUNT(*) as cnt FROM eval where empid=$empid") as $test) { 
    echo "<table ><tr ><td style='border: 0px; '>" . $test['cnt'] . "</td></tr></table>"; 
} 

?> 

total score query 
========================== 


foreach($dbh->query("SELECT SUM(totalscore) as cnt FROM eval where empid = $empid") as $leavecount) { 
    echo "<table ><tr ><td style='border: 0px; ' >" . $leavecount['cnt'] . "</td></tr></table>"; 
} 
?> 

回答

0

结合该行查询

foreach($dbh->query("SELECT COUNT(*) as cnt, SUM(totalscore) as totalscore, SUM(totalscore)/SUM(totalevaluatedcalls) as averagescore 
       FROM eval 
       where empid= $empid 
      ") as $test) 
        { 
echo "<table ><tr ><td style='border: 0px; '>" . $test['cnt'] . "</td><td style='border: 0px; '>" . $test['totalscore'] . "</td><td style='border: 0px; '>" . $test['averagescore'] . "</td></tr></table>";  

      } 
0

使用查询作为

foreach($dbh->query("select count(*) as cnt,sum(totalscore) as tot from eval where empid=$empid") as $data) 
{ 
    $avg=($data['cnt']/$data['tot'])*100; 
}