Good time to all!
The commonplace task is to create a query (or several) from many tables to create a pivot table.
There are 5 tables:
lessons with fields: id|title|date
evals with the fields id|eval|lesson_id|pupil_id|subject_id|date
subjects with fields: id|title
pupils (students) with fields: id|firstname|lastname
absent (blanks) with fields: id|pupil_id|lesson_id
Create a table in the form of a school magazine page:
N is any number (that is, the number of students and lessons is arbitrary).
I solved the problem using cycles in php. It works fine while the records in the tables are few. As soon as there are a couple of million estimates, half a million lessons, then it hangs terribly. Tell me a way to avoid loops. Direct on the right decision. Thank you in advance!
Update
My question is to find out how to get all the data at once. I tried to "blind" all the tables with join:
select `evals`.`pupil_id` `pupil_id`, `evals`.`lesson_id` `lesson_id`, `evals`.`eval` `eval`, `evals`.`id` `eval_id` from `evals` `evals` join `lessons` `lessons` on `evals`.`lesson_id`=`lessons`.`id` left join `absent` `absent` on `absent`.`pupil_id`=`evals`.`pupil_id` where `evals`.`subject_id`=10 and `lessons`.`date` between '1409515200' and '1420920000'
evals
.pupil_id
pupil_id
,evals
.lesson_id
lesson_id
,evals
.eval
eval
,evals
.id
eval_id
fromevals
lesson_id
=lessons
.id
left joinabsent
absent
onabsent
.pupil_id
=evals
.pupil_id
whereevals
.subject_id
= 10 andlessons
.date
between '1409515200' and '1420920000' - Agloval