次のような 7 つのテーブルがあるとします。
class_teacher_lesson
class_teacher_lession_ID, class_ID, teacher_ID, lesson_ID
クラス
class_ID, class
先生
teacher_ID, teacher
レッスン
lesson_ID, lesson
学生
student_ID, class_ID, ..., ....
調査回答
survey_answer_ID, survey_question_ID, class_teacher_lession_ID, survey_answer
調査質問
survey_question_ID, survey_question,
結果は次のようになります。
ループでこれを取得します:
レッスン数学:
survey_question (where teacher_id = 11 and lesson_id = 13):
Total Students Total Students Answered Survey survey_answer AVG
155 45 79%
survey_question 2 (where teacher_id = 11 and lesson_id = 13):
Total Students Total Students Answered Survey survey_answer AVG
155 99 87%
レッスン英語:
survey_question (where teacher_id = 11 and lesson_id = 15):
Total Students Total Students Answered Survey survey_answer AVG
90 20 50%
survey_question 2 (where teacher_id = 11 and lesson_id = 15):
Total Students Total Students Answered Survey survey_answer AVG
90 25 34%
これまでのところ、私はこれを試しました:
SELECT teacher AS 'Teacher', class AS 'Class', lesson AS 'Lesson',
COUNT(student_ID) AS 'Number of students',
COUNT(enquete_antwoord_ID) AS 'Total students answered survey',
enquete_vraag AS 'Survey Question'
FROM Teacher
LEFT JOIN class_teacher_lesson
ON teacher.teacher_ID = class_teacher_lesson.teacher_ID
LEFT JOIN lesson
ON class_teacher_lesson.class_ID = lesson.lesson_ID
LEFT JOIN class
ON class_teacher_lesson.class_ID = class.class_ID
LEFT JOIN student
ON class.class_ID = student.class_ID
LEFT JOIN survey_answer
ON class_teacher_lesson.class_teacher_lesson_ID =
survey_answer.class_teacher_lesson
LEFT JOIN survey_question
ON survey_answer.survey_question_ID = survey_question.survey_question_ID
WHERE teacher.teacher_ID = '1158' AND lesson.lesson_ID = '449'
GROUP BY class.class, lesson.lesson, teacher.teacher,
survey_answer.survey_answer, survey_question
この結果:
Teacher: Class: Lesson: Number of students: Filled in: Survey_question:
t1 c1 math 54 54 question1?
t1 c1 math 24 0 NULL
t1 c1 math 22 0 NULL
結果は次のようになります。
Teacher: Class: Lesson: Number of students: Filled in: Survey_question:
t1 c1 math 90 54 question1?