Skip to content

Instantly share code, notes, and snippets.

@Rudersonvf
Created February 18, 2023 22:46
Show Gist options
  • Save Rudersonvf/bc298d89c8a2cdfba8a1ccde53391a45 to your computer and use it in GitHub Desktop.
Save Rudersonvf/bc298d89c8a2cdfba8a1ccde53391a45 to your computer and use it in GitHub Desktop.
--Questão 1
SELECT nome AS curso, numero AS turma, inicio
FROM tb_curso
INNER JOIN tb_turma ON tb_curso.id = tb_turma.curso_id
--Questão 2
SELECT tb_curso.nome AS curso, numero AS turma, tb_aluno.nome AS aluno, cpf
FROM tb_curso
INNER JOIN tb_turma ON tb_curso.id = tb_turma.curso_id
INNER JOIN tb_matricula ON tb_turma.id = tb_matricula.turma_id
INNER JOIN tb_aluno ON tb_matricula.aluno_id = tb_aluno.cpf
--Questão 3
SELECT data, nota, nome, nota_obtida, ROUND((nota_obtida/nota)*100,2) AS porcentagem
FROM tb_aluno
INNER JOIN tb_resultado ON tb_aluno.cpf = tb_resultado.aluno_id
INNER JOIN tb_avaliacao ON tb_resultado.avaliacao_id = tb_avaliacao.id
ORDER BY data DESC, nome ASC
--Questão 4
SELECT nome, SUM(nota_obtida) AS total
FROM tb_aluno
INNER JOIN tb_resultado ON tb_aluno.cpf = tb_resultado.aluno_id
INNER JOIN tb_avaliacao ON tb_resultado.avaliacao_id = tb_avaliacao.id
INNER JOIN tb_turma ON tb_avaliacao.turma_id = tb_turma.id
WHERE tb_turma.numero = 10
GROUP BY nome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment