我有一个成员表(可以并且应该已经规范化)但它包含以下信息:
**members**
member_id
firstName
lastName
score_1
score_2
score_3
score_4
score_5
score_6
score_7
score_8
我要做的是将所有这些分数加起来,找出哪一个总分是最低分,然后输出成员firstName
我昨天得到的帮助总体上得到了最低价值,但我很难找到一种方法将最终得分改为输出一串成员名称。
$lowScoreResult = $conn->query("SELECT team_members.team_id, team_members.member_id, members.member_id, members.firstName, members.lastName, SUM(members.score_1) `score_1`, SUM(members.score_2) `score_2`, SUM(members.score_3) `score_3`, SUM(members.score_4) `score_4`, SUM(members.score_5) `score_5`, SUM(members.score_6) `score_6`, SUM(members.score_7) `score_7`, SUM(members.score_8) `score_8`
FROM team_members
JOIN members
ON team_members.member_id = members.member_id
WHERE members.dashboard_id = $dashboard_id AND team_members.team_id = $teamSelect");
while($row=mysqli_fetch_array($lowScoreResult, MYSQLI_ASSOC)) {
$low1[] = $row['score_1'];
$low2[] = $row['score_2'];
$low3[] = $row['score_3'];
$low4[] = $row['score_4'];
$low5[] = $row['score_5'];
$low6[] = $row['score_6'];
$low7[] = $row['score_7'];
$low8[] = $row['score_8'];
}
$low_score_1 = min($low1);
$low_score_2 = min($low2);
$low_score_3 = min($low3);
$low_score_4 = min($low4);
$low_score_5 = min($low5);
$low_score_6 = min($low6);
$low_score_7 = min($low7);
$low_score_8 = min($low8);
// lowest of the entire set
$t = array($low_score_1,$low_score_2,$low_score_3,$low_score_4,$low_score_5,$low_score_6,$low_score_7,$low_score_8);
所以当前的输出形式是一个数字值,它是来自特定列的超过分数,i,e score_1,score_2等,因为这些列是部门的分数,所以score_1是部门1的部门1 score_2等。 ..我需要一种方式来表示所显示的整体价值来自部门1,如果它来自那里......
答案 0 :(得分:1)
我没有在我的控制台上试过它,但它应该让你对caluculatinf有一些了解,在查询本身中字段名称详细信息的得分最低
select team_members.team_id, team_members.member_id, members.member_id, members.firstName, members.lastName,
min(score_1),min(score_2),min(score_3),min(score_4),min(score_5),min(score_6),min(score_7),min(score_8)
from ( select team_members.team_id, team_members.member_id, members.member_id, members.firstName, members.lastName,
SUM(members.score_1) `score_1`, SUM(members.score_2) `score_2`, SUM(members.score_3) `score_3`, SUM(members.score_4) `score_4`, SUM(members.score_5) `score_5`, SUM(members.score_6) `score_6`, SUM(members.score_7) `score_7`, SUM(members.score_8) `score_8`from
team_members
JOIN members
ON team_members.member_id = members.member_id
WHERE members.dashboard_id = $dashboard_id AND team_members.team_id = $teamSelect
) as t;