我试图连续获得锻炼的总和,然后按总和对所有行进行排序,以获得团队所在的位置,因此以正确的顺序列出。我现在试图弄清楚这一点,我对自己的逻辑有点迷失了。我了解 MYSQL sum 函数,但似乎看不到在这种情况下如何使用它来帮助我。
所以是这样的:
这是我当前的表架构:
CREATE TABLE workouts
(
team_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
username VarChar(255) NOT NULL,
team_name VarChar(50) NOT NULL,
week1 INT NOT NULL,
week2 INT NOT NULL,
week3 INT NOT NULL,
week4 INT NOT NULL,
week5 INT NOT NULL,
week6 INT NOT NULL,
week7 INT NOT NULL,
week8 INT NOT NULL,
week9 INT NOT NULL,
week10 INT NOT NULL,
week11 INT NOT NULL,
week12 INT NOT NULL
) engine=innodb;
到目前为止,这是我的展示:
<?php
$count = 0;
$statement = $db->query('SELECT * FROM workouts');
foreach($statement as $row):
?>
<tr>
<td><?php $count++; ?></td>
<td><?php $row['team_name']; ?></td>
<td><?php $row['week1']; ?></td>
<td><?php $row['week2']; ?></td>
<td><?php $row['week3']; ?></td>
<td><?php $row['week4']; ?></td>
<td><?php $row['week5']; ?></td>
<td><?php $row['week6']; ?></td>
<td><?php $row['week7']; ?></td>
<td><?php $row['week8']; ?></td>
<td><?php $row['week9']; ?></td>
<td><?php $row['week10']; ?></td>
<td><?php $row['week11']; ?></td>
<td><?php $row['week12']; ?></td>
<td><?php ?></td>
</tr>
<?php endforeach; ?>