It is necessary to know the name of the students whose average grade of programming of the second year is higher than that of the program.
Here I enclose my query:
select nombre
from alumno innner join matricula on (alumno.#a=matricula.#a)
where (select avg(nota)
from matricula inner join asignatura on (matricula.#asig=asignatura.#asig)
where (nombre like 'bd') and (nota >(select avg(nota)
from matricula inner join asignatura on (matricula.#asig=asignatura.#asig)
where (nombre like 'programación'));
Structure of the database:
create table alumno(
a smallint not null constraint PK_Alumno primary key,
nombre varchar (50) not null
);
create table profesor (
p smallint not null constraint PK_Prof primary key,
nombre varchar (50) not null);
create table asignatura (
asig smallint not null constraint PK_ASIG primary key,
nombre varchar (50) not null);
create table matrícula (
asig smallint not null,
a smallint not null,
nota numeric (2,0) not null
constraint Pk_MATR primary key (asig),
constraint FK_MATR_AL foreign key (a) references alumno (a) on update cascade on delete cascade,
constraint FK_MATR_AS foreign key (asig) references asignatura (asig) on update cascade on delete cascade);
create table imparte(
p smallint not null,
asig smallint not null,
curso varchar (30) not null,
constraint PK_impart primary key (p,asig),
constraint FK_IMPARTE_P foreign key (p) references profesor (p) on update cascade on delete cascade,
constraint FK_IMPARTE_ASIG foreign key (asig) references asignatura (asig) on update cascade on delete cascade);