0

我有一个类似于以下的数据库:

+------------+-----------+------------+
| student_id |  subject  | test score |
+------------+-----------+------------+
|          3 | math      |         78 |
|          3 | physics   |         66 |
|          3 | english   |         98 |
|          2 | math      |         76 |
|          2 | physics   |         57 |
|          2 | geology   |         87 |
|          2 | english   |         99 |
|          1 | math      |         86 |
|          1 | physics   |         85 |
|          1 | astronomy |         89 |
|          1 | history   |         77 |
+------------+-----------+------------+

我想对subject_ids进行分组。第二列中的标签将成为列,新行将成为分数。所以它应该看起来像这样:

+------------+------+---------+---------+---------+-----------+
| student_id | math | physics | english | geology | astronomy |
| 1          | 86   | 85      |         |         | 89        |
| 2          | 76   | 57      | 99      | 87      |           |
| 3          | 78   | 66      | 98      |         |           |
+------------+------+---------+---------+---------+-----------+
4

0 回答 0