-- Aluno(nroAluno, nomeAluno, formação, nivel, idade) -- Curso(nome, horario, sala, idProf) -- Matriculado(nroAluno, nomeCurso) -- Professor(idProf, nomeProf, idDepto) -- 1) Encontre os nomes de todos os cursos que são ministrados na sala R128. select nome from Curso as C where sala = 'R128'; -- 2) Encontre o nome de todos os Juniores (nível = JR) que estão matriculados em um curso ministrado por Ivana Teach. select A.nomeAluno from Aluno as A, Curso as C, Professor as P, Matriculado as M where A.nivel='JR' and P.nomeProf = 'Ivana Teach' and C.idProf = P.idProf and M.nomeCurso = C.nome and M.nroAluno = A.nroAluno; -- 3) Encontre os nomes de todos os alunos que estão matriculados em dois cursos que são ministrados no mesmo horário. select nomeAluno from Aluno A, Matriculado as M1, Matriculado as M2, Curso as C1, Curso as C2 where A.nroAluno = M1.nroAluno and M1.nroAluno = M2.nroAluno and M1.nomeCurso <> M2.nomeCurso and M1.nomeCurso = C1.nome and M2.nomeCurso = C2.nome and C1.horario = C2.horario; -- 4) Encontre os nomes dos alunos matriculados em nenhum curso. select nomeAluno from Aluno where nroAluno not in ( select nroAluno from matriculado ); -- 5) Encontre o nome do aluno mais velho que é matriculado em um curso ministrado pelo Ivana Teach. select nomeAluno from Aluno A, Matriculado M where A.nroAluno = M.nroAluno and nomeCurso in ( select nome from Curso C, Professor P where C.idProf = P.idProf and nomeProf = 'Ivana Teach' ) and idade = ( select max(idade) from Aluno A2, Matriculado M2 where A2.nroAluno = M2.nroAluno and nomeCurso in ( select nome from Curso C2, Professor P2 where C2.idProf = P2.idProf and nomeProf = 'Ivana Teach' ) ); -------------------------- -- Resolução alternativa select nomeAluno from Aluno where nroAluno in ( select A2.nroALuno from Aluno as A2, Curso as C, Professor as P, Matriculado as M where P.nomeProf = 'Ivana Teach' and C.idProf = P.idProf and M.nomeCurso = C.nome and M.nroAluno = A2.nroAluno ) and idade >= all ( select A1.idade from Aluno as A1 where A1.nroAluno in ( select A2.nroALuno from Aluno as A2, Curso as C, Professor as P, Matriculado as M where P.nomeProf = 'Ivana Teach' and C.idProf = P.idProf and M.nomeCurso = C.nome and M.nroAluno = A2.nroAluno)); -- 6) Encontre os nomes dos professores que ministram cursos em todas as salas em que algum curso é ministrado. select nomeProf from professor as P where not exists ( select sala from curso as C where not exists ( select from curso where C.sala = sala and idProf = P.idProf ) ); -------------------------- -- Resolução alternativa select nomeProf from professor as P where not exists ( (select distinct sala from curso) ----> Todas as salas except ----> Obtém as salas nas quais o prof. P não ministra cursos (select distinct sala from curso where idProf = P.idProf) -----> Salas do prof. P );