The column '<column name>' is invalid in the selection list because it is not contained in an aggregation function or in the GROUP BY clause

Asked

Viewed 96 times

0

Hello!

In the system there is data collection for some questions and the answers are 0-100. My database has the following tables: Person, Question, Personal.

I’m trying to get a select where to return the question id, the question itself and the average answer between that question. To do such action I am using the following query:

SELECT ppr.IdPergunta, p.Pergunta , AVG(ppr.Valor) as MediaPergunta FROM Pessoa_Pergunta_Resposta ppr, Perguntas p WHERE ppr.IdPergunta = p.Id GROUP BY ppr.IdPergunta

But it gives the titled error. I know the question should be in the aggregation function or group by, but from what I learned, it would not make sense to put it. They would have some light?

Thank you!

  • Change your clause GROUP BY ppr.IdPergunta for GROUP BY ppr.IdPergunta, p.Pergunta. Why do you think you should not put it in the GROUP BY clause?

  • i had tried this, and had given error... Now with your query worked, I was doing something wrong. Thank you!

No answers

Browser other questions tagged

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