0

だから私は3つのテーブルを持っています:

student
-studentid
-studentname

course_offerings
-course_offeringid
-course
-type

scores
-student_studentid
-course_offering_course_offeringid
-score

クエリを実行すると:

SELECT studentid, studentname, course, type, score
FROM scores
INNER JOIN student ON scores.student_studentid = student.studentid
INNER JOIN course_offering ON scores.course_offering_course_offeringid = course_offering.course_offeringid

次のような出力が得られます。

studentid   studentname     course  type    score
123345      Doe, John       123     Exam 1  100
123345      Doe, John       123     Exam 2  95
123345      Doe, John       123     Exam 3  75
123345      Doe, John       123     Final   93
543211      Doe, Jane       123     Exam 1  70
543211      Doe, Jane       123     Exam 2  91
543211      Doe, Jane       123     Exam 3  99
543211      Doe, Jane       123     Final   43
.
.
.

私が望むのは、出力が次のようになることです。

studentid   studentname     course  Exam 1  Exam 2  Exam 3  Final
123345      Doe, John       123     100     95       75     93
543211      Doe, Jane       123     70      91      99      43

これは MySQL だけで可能ですか?

4

2 に答える 2

0

試験の量をハードコーディングしないわけではありません。学生を連れて、試験に3回参加して、first id < secondid < thirdid ダブルスが起こらないようにすることができます.

追加の試験が必要な場合、または誰かが 2 つの試験しか受けていない場合は、それに対処する必要があります。この種のピボットは、3 つ (またはそれ以上/以下) の結合をハードコーディングしないと不可能です。

于 2013-05-30T13:21:08.517 に答える