2016-10-04 13 views
0

私はPHPでそれをやったことができますtotalscore/totalevaluatedcallsによって実行時に平均を計算したい...そしてここに私のcode.any誰かが私を助けることができるこの点に関する評価された合計呼び出しは、dbからのemp idの数です。平均的なスコアを得る方法

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; 
} 
関連する問題