gpt4 book ai didi

mysql - 输出MySQL结果

转载 作者:行者123 更新时间:2023-11-30 01:36:16 24 4
gpt4 key购买 nike

所以我有 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 就可以做到这一点吗?

最佳答案

如果没有对考试数量进行硬编码,就不行。您可以带领学生参加 3 次不同的考试,确保first id < secondid < thirdid阻止 double 的发生。

如果你需要额外的考试,或者某人只有两次考试,你就需要处理它。如果不对 3 个(或更多/更少)连接进行硬编码,这种类型的数据透视是不可能实现的

关于mysql - 输出MySQL结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16837295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com