PHP列中的所有内容的总和

时间:2017-02-23 16:03:32

标签: php mysqli

我根据用户的得分计算了平均值,如下:

      $score1 = $row["score1"];
      $score2 = $row["score2"];
      $score3 = $row["score3"];
      $score4 = $row["score4"];
      $score5 = $row["score5"];
      $score6 = $row["score6"];
      $score7 = $row["score7"];
      $score8 = $row["score8"];

      $sum = $score1 + $score2 + $score3 + $score4 + $score5 + $score6 + $score7 + $score8;
      $totalAverage = $sum / 8;

这给了我每个人的平均值。我需要做的是通过将每个人得分相加并输出最终总数得到总平均数,如果有意义的话?

这是我的选择请求:

$sql = "SELECT member.id, member.firstName, member.lastName, compScore.score1, compScore.score2, compScore.score3, compScore.score4, compScore.score5, compScore.score6, compScore.score7, compScore.score8, compScore.memberId, teamMember.memberId, teamMember.teamId
        FROM member
        LEFT JOIN compScore
        ON member.id = compScore.memberId
        LEFT JOIN teamMember
        ON teamMember.memberId = member.id
        WHERE teamMember.teamId = $teamData";

我有一个得分表,收集所有得分(总是只有一组8),但得到每个人得分,然后平均得分。

0 个答案:

没有答案