列出主题中的所有团队和团队成员详细信息

List all teams and team member details in a subject

我在编写查询时遇到了一些问题。我希望能够列出所有团队,以及团队中某一学科的学生。

这是我的表格种类。

Team (teamID, teamName, subjectID)
Student(studentID, Student Name)
AssignTeam(AssignID, studentID, teamID)
Subject(subjectID, subjectName)

这就是我希望输出的样子。

Team 1 - Team Name
Student 1 ID - Student 1 Name 
Student 2 ID - Student 2 Name 
Student 3 ID - Student 3 Name 
Student 4 ID - Student 4 Name 

Team 2 - Team Name
Student 1 ID - Student 1 Name 
Student 2 ID - Student 2 Name 
Student 3 ID - Student 3 Name 
Student 4 ID - Student 4 Name
Student 5 ID - Student 5 Name

Team 3 - Team Name
Student 1 ID - Student 1 Name 
Student 2 ID - Student 2 Name 
Student 3 ID - Student 3 Name 

我正在努力弄清楚如何以这样一种方式对其进行格式化以包括各组之间的休息时间。我真的只知道如何制作一个看起来像这样的列表

Group   StuID   StuName
--      ----    ----
1       1       Mike
1       2       Stacey
1       3       Jenny   
2       4       Rick
2       5       Sam
3       6       Larry
3       4       Anita

我想使用 mySQL 构建列表,但它最终将通过 PHP 输出。我希望创建一个存储过程,然后我可以调用它并将 subjectID 传递到其中,然后创建列表。

我还没有完全弄清楚是一个过程会创建列表并转换为字符串以供输出,还是应该是两个单独的查询。

如有任何建议,我们将不胜感激。

谢谢

这不是 mysql 的解决方案,但是从 mysql 中读取 PHP 中的行是否不够简单,并且当组更改时输出 header 该组的行?
请参阅下面的代码段。您必须使 outputRow() 和 outputGroupHeader() 以您需要的格式生成输出。

<?php
$lastgroup = "";
while ($row = mysqli_fetch_assoc($query))
{
  if ($row['group'] != $lastgroup) {
    outputGroupHeader($row['group']);
    $lastgroup = $row['group'];
  }
  outputRow($row);
}