How to use aggregation functions in a WHERE?

Asked

Viewed 74 times

0

I’m doing a college paper on databases, and one of the Query what I must do is this:

  • Show all creditors who had a larger purchase total than that R$ 5000,00;

I tried to:

SELECT NomeCredor, SUM(Compras.Valor)

FROM Credores, Compras

WHERE (idCredores = Compras.Credores_idCredores)

AND (SUM(Compras.Valor)) > 5000

GROUP BY NomeCredor

ORDER BY NomeCredor;

The problem is that the SUM(Compras.Valor) cannot be passed as a condition of WHERE. Does anyone know an alternative?

1 answer

3

  • 1

    Good John, I believe your answer is correct!

  • 1

    It worked! Thank you very much. I will read about the HAVING clause.

Browser other questions tagged

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