вот мои столы
eleve
стол
+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| idEleve | int(11) | NO | PRI | NULL | |
| NomEleve | varchar(30) | YES | | NULL | |
| PrenomEleve | varchar(30) | YES | | NULL | |
| DateNaissEleve | date | YES | | NULL | |
| LieuNaissEleve | varchar(30) | YES | | NULL | |
| codeClasse | varchar(30) | YES | MUL | NULL | |
+----------------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
mysql> select *from eleve ;
+---------+-----------+-------------+----------------+----------------+------------+
| idEleve | NomEleve | PrenomEleve | DateNaissEleve | LieuNaissEleve | codeClasse |
+---------+-----------+-------------+----------------+----------------+------------+
| 1 | brahim | elmoctar | 1996-08-19 | teyaret | CP1 |
| 2 | mohamed | elmoctar | 2000-02-01 | teyaret | CP2 |
| 3 | fatimetou | elmoctar | 1995-05-19 | teyaret | CP3 |
+---------+-----------+-------------+----------------+----------------+------------+
note
стол
mysql> desc note ;
+-------------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+---------+------+-----+---------+-------+
| idAffectationProf | int(11) | YES | MUL | NULL | |
| idEleve | int(11) | YES | MUL | NULL | |
| NoteTrimester1 | double | YES | | NULL | |
| NoteTrimester2 | double | YES | | NULL | |
| NoteTrimester3 | double | YES | | NULL | |
+-------------------+---------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> select * from note ;
+-------------------+---------+----------------+----------------+----------------+
| idAffectationProf | idEleve | NoteTrimester1 | NoteTrimester2 | NoteTrimester3 |
+-------------------+---------+----------------+----------------+----------------+
| 1 | 1 | 13.24 | 12.45 | 10.54 |
| 2 | 1 | 10.24 | 17.45 | 18.54 |
| 3 | 1 | 15.24 | 12.45 | 13.54 |
+-------------------+---------+----------------+----------------+----------------+
3 rows in set (0.00 sec)
affectationMatiere
стол
mysql> desc affectationMatiere ;
+-------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+-------------+------+-----+---------+-------+
| idAffectationProf | int(11) | NO | PRI | NULL | |
| codeClasse | varchar(30) | YES | MUL | NULL | |
| idProf | int(11) | YES | MUL | NULL | |
| codeMat | varchar(30) | YES | MUL | NULL | |
| Annee | date | YES | | NULL | |
+-------------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> select *from affectationMatiere ;
+-------------------+------------+--------+---------+------------+
| idAffectationProf | codeClasse | idProf | codeMat | Annee |
+-------------------+------------+--------+---------+------------+
| 1 | CP1 | 1 | Math | 2020-01-01 |
| 2 | CP2 | 2 | PC | 2020-02-02 |
| 3 | CP3 | 1 | SN | 2020-03-03 |
+-------------------+------------+--------+---------+------------+
3 rows in set (0.00 sec)
moyenne
таблица
mysql> desc moyenne ;
+---------------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------+------+-----+---------+-------+
| idEleve | int(11) | YES | MUL | NULL | |
| Annee | date | NO | PRI | NULL | |
| moyenneGlobaleEleve | double | YES | | NULL | |
+---------------------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)
Я хочу вставить idEleve
, Annee
и общее среднее значение каждого студента в таблицу moyenne
.
Вот мой query:
INSERT INTO moyenne
SELECT E.idEleve,a.Annee, (note.NoteTrimester1 + note.NoteTrimester2 + note.NoteTrimester3)/3 AS NoteGlobal FROM eleve E,affectMatiere a, note;
но, к сожалению, запрос возвращает 27 результатов вместо 3. внезапно я выполнил запрос без вставки в, и вот что я нашел
mysql> SELECT E.idEleve,a.Annee, (note.NoteTrimester1 + note.NoteTrimester2 + note.NoteTrimester3)/3 AS NoteGlobal FROM eleve E,affectationMatiere a, note;
+---------+------------+--------------------+
| idEleve | Annee | NoteGlobal |
+---------+------------+--------------------+
| 1 | 2020-01-01 | 12.076666666666666 |
| 2 | 2020-01-01 | 12.076666666666666 |
| 3 | 2020-01-01 | 12.076666666666666 |
| 1 | 2020-02-02 | 12.076666666666666 |
| 2 | 2020-02-02 | 12.076666666666666 |
| 3 | 2020-02-02 | 12.076666666666666 |
| 1 | 2020-03-03 | 12.076666666666666 |
| 2 | 2020-03-03 | 12.076666666666666 |
| 3 | 2020-03-03 | 12.076666666666666 |
| 1 | 2020-01-01 | 15.409999999999998 |
| 2 | 2020-01-01 | 15.409999999999998 |
| 3 | 2020-01-01 | 15.409999999999998 |
| 1 | 2020-02-02 | 15.409999999999998 |
| 2 | 2020-02-02 | 15.409999999999998 |
| 3 | 2020-02-02 | 15.409999999999998 |
| 1 | 2020-03-03 | 15.409999999999998 |
| 2 | 2020-03-03 | 15.409999999999998 |
| 3 | 2020-03-03 | 15.409999999999998 |
| 1 | 2020-01-01 | 13.743333333333332 |
| 2 | 2020-01-01 | 13.743333333333332 |
| 3 | 2020-01-01 | 13.743333333333332 |
| 1 | 2020-02-02 | 13.743333333333332 |
| 2 | 2020-02-02 | 13.743333333333332 |
| 3 | 2020-02-02 | 13.743333333333332 |
| 1 | 2020-03-03 | 13.743333333333332 |
| 2 | 2020-03-03 | 13.743333333333332 |
| 3 | 2020-03-03 | 13.743333333333332 |
+---------+------------+--------------------+
27 rows in set (0.00 sec)