这是我的数据库架构
学生表:
var arr = [
[
"1947-01-01",
243.1
],
[
"1947-04-01",
246.3
],
[
"1947-07-01",
250.1
]
];
var output = arr.map(s => ({
date: s[0],
gdp: s[1]
}));
console.log(output);
班级表:
studentid (PK) |studentname
1 |A
教学表:
classid (PK) |classname
1 |Math
2 |Science
测验表:
teachid (PK) | classid | studentid
1 | 1 | 1
2 | 2 | 1
quizscore table:
quizid (PK) |classid | quizname
1 |1 | mathquiz
2 |2 | science quiz
这是我使用的SQL查询:
quizscoreid(PK) | quizid |studentid |score
1 | 1 |1 |60
2 | 2 |1 |0
及其输出如下:
SELECT
quiz.quizid,
teach.classid,
student.studentname,
student.studentid,
quizscore.score,
quiz.quizname,
class.classname
FROM teach
INNER JOIN class
ON teach.classid = class.classid
INNER JOIN student
ON teach.studentid = student.studentid
INNER JOIN quiz
ON quiz.classid = '1'
LEFT JOIN quizscore
ON teach.studentid = quizscore.studentid
WHERE
teach.classid='1' AND
teach.classid = quiz.classid AND
quiz.quizid = '1'
ORDER BY studentid ASC
虽然我期待这样:
studentid |quizid |classid | studentname |classname | quizname | score
1 | 1 |1 | A |Math | mathquiz | 60
1 | 1 |1 | A |Science | mathquiz | 0
请帮我纠正我的SQL查询
答案 0 :(得分:0)
SELECT
A.studentid,
D.quizid,
A.classid,
C.studentname,
B.classname,
D.quizname,
E.score
FROM
teach A
LEFT JOIN class B ON A.classid=B.classid
LEFT JOIN student C ON A.studentid=C.studentid
LEFT JOIN quiz D ON A.classid=D.classid
LEFT JOIN quizscore E ON D.quizid=E.quizid AND E.studentid=A.studentid
WHERE
A.studentid=1 AND
D.quizid=1 AND
A.classid=1;