Exemples SQL

#1. Quelle est l'épreuve qui a la meilleure moyenne ?
create view v_moyennes
as select numEpreuve, max(moyenne)
from note
group by numEpreuve;

select numEpreuve
from v_moyennes
where moyenne = (select max(moyenne) from v_moyennes);

#2. Utiliser des vues pour insérer
create view v_notes_gpre_1
as select note.*
from note
join participation on note.numEtudiant = participation.numEtudiant
where participation.numGroupe = 1;

insert into v_notes_gpre_1 (numEtudiant, numEpreuve, note) values (2, 8, 11);

#2.2 avec le check option
create view v_notes_gpre_2
as select note.*
from note
join participation on note.numEtudiant = participation.numEtudiant
where participation.numGroupe = 2
with check option;

insert into v_notes_gpre_1 (numEtudiant, numEpreuve, note) values (1, 5, 3);