MySQL 查询帮助
以下是我正在使用的表的描述:
describe mjla_db.StudentRecordTable2;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| classId | varchar(20) | NO | MUL | NULL | |
| studentId | varchar(20) | NO | MUL | NULL | |
| quizGrade | tinyint(4) | YES | | NULL | |
| quizId | int(11) | NO | MUL | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
这是数据库中的示例数据:
+------------+-----------+------------+---------+------------+
| Student ID | Last Name | First Name | Quiz ID | Quiz Grade |
+------------+-----------+------------+---------+------------+
| A1 | Cat | Tom | 19 | 75 |
| A2 | pancake | Harry | 19 | 65 |
| A5 | Worthy | Dick | 19 | NULL |
| A1 | Cat | Tom | 20 | 55 |
| A2 | pancake | Harry | 21 | NULL |
| A2 | pancake | Harry | 20 | 47 |
| A5 | Worthy | Dick | 20 | 95 |
| A1 | Cat | Tom | 21 | 55 |
| A5 | Worthy | Dick | 21 | 95 |
+------------+-----------+------------+---------+------------+
3 rows in set (0.00 sec)
我试图获得的结果类似于以下内容:
+------------+-----------+------------+---------+------------+------------+
| Student ID | Last Name | First Name | Quiz 19 | Quiz 20 | Quiz 21 |
+------------+-----------+------------+---------+------------+------------+
| A1 | Cat | Tom | 75 | 55 | 55 |
| A2 | pancake | Harry | 65 | 47 | NULL |
| A5 | Worthy | Dick | NULL| 95 | 95 |
+------------+-----------+------------+---------+------------+------------+
- 其中学生 ID 列是唯一的。
- 测验列的继续位置取决于测验的数量 原来的表。测验栏包含每个的成绩 各自的学生。
Here is a description of the table i am using:
describe mjla_db.StudentRecordTable2;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| classId | varchar(20) | NO | MUL | NULL | |
| studentId | varchar(20) | NO | MUL | NULL | |
| quizGrade | tinyint(4) | YES | | NULL | |
| quizId | int(11) | NO | MUL | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
Here is example data in the database:
+------------+-----------+------------+---------+------------+
| Student ID | Last Name | First Name | Quiz ID | Quiz Grade |
+------------+-----------+------------+---------+------------+
| A1 | Cat | Tom | 19 | 75 |
| A2 | pancake | Harry | 19 | 65 |
| A5 | Worthy | Dick | 19 | NULL |
| A1 | Cat | Tom | 20 | 55 |
| A2 | pancake | Harry | 21 | NULL |
| A2 | pancake | Harry | 20 | 47 |
| A5 | Worthy | Dick | 20 | 95 |
| A1 | Cat | Tom | 21 | 55 |
| A5 | Worthy | Dick | 21 | 95 |
+------------+-----------+------------+---------+------------+
3 rows in set (0.00 sec)
The result i am trying to get is one that will look similar to the following:
+------------+-----------+------------+---------+------------+------------+
| Student ID | Last Name | First Name | Quiz 19 | Quiz 20 | Quiz 21 |
+------------+-----------+------------+---------+------------+------------+
| A1 | Cat | Tom | 75 | 55 | 55 |
| A2 | pancake | Harry | 65 | 47 | NULL |
| A5 | Worthy | Dick | NULL| 95 | 95 |
+------------+-----------+------------+---------+------------+------------+
- Where the Student ID column is unique.
- Where the quiz columns continue depending on how many quizzes are in
the original table. And the quiz columns contain the grade of each of
the respective students.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
参见这个
try this:
see this