How to select the highest value of the following query?

Asked

Viewed 73 times

-1

SELECT SUM(DISCIPLINA.VALOR) + MATRICULA.VALOR
    FROM ALUNO, MATRICULA, MATDISCIPLINA, DISCIPLINA, SEMESTRE
    WHERE ALUNO.CDALUNO = MATRICULA.CDALUNO
        AND MATRICULA.CDSEMESTRE = SEMESTRE.CDSEMESTRE
        AND MATRICULA.CDMATRICULA = MATDISCIPLINA.CDMATRICULA 
        AND MATDISCIPLINA.CDDISCIPLINA = DISCIPLINA.CDDISCIPLINA
        AND SEMESTRE.ANO = '2018.1'
    GROUP BY ALUNO.NOME
  • Have you tried placing SELECT values between the max() ? , more or less like this: SELECT max(SUM(DISCIPLINA.VALOR) + MATRICULA.VALOR) ?

  • Already tried mysql returns this error: ERROR 1111 (HY000): Invalid use of group Function

  • Use: SUM(DISCIPLINA.VALOR) + SUM(MATRICULA.VALOR)

1 answer

1


Just use the above query as subquery:

SELECT MAX(x.total)
  FROM (
  SELECT SUM(DISCIPLINA.VALOR) + MATRICULA.VALOR AS total
    FROM ALUNO, MATRICULA, MATDISCIPLINA, DISCIPLINA, SEMESTRE
   WHERE ALUNO.CDALUNO = MATRICULA.CDALUNO
     AND MATRICULA.CDSEMESTRE = SEMESTRE.CDSEMESTRE
     AND MATRICULA.CDMATRICULA = MATDISCIPLINA.CDMATRICULA 
     AND MATDISCIPLINA.CDDISCIPLINA = DISCIPLINA.CDDISCIPLINA
     AND SEMESTRE.ANO = '2018.1'
   GROUP BY ALUNO.NOME
) x
  • Thank you colleague.

  • @Hiagopais if the answer answered you do not forget to accept it

Browser other questions tagged

You are not signed in. Login or sign up in order to post.