0
Tabela - lista
id | nota
1 | 10
2 | 8
3 | 7
1 | 8
3 | 9
I want to average the notes of those who have the same ID, and for that I created the following query:
SELECT AVG(nota) FROM lista GROUP BY id
With this query I wanted to remove all the information from another table from the id depending on the average they have, for example if the average of an id is higher than 9 are listed the names of these ids that are in another table.
Tabela - informacao
id | nome
1 | Teste1
2 | Teste2
3 | Teste3
4 | Teste4
By my search it is necessary to exist a query inside another only that will always result in error because it is not possible to compare the average of several results with a number. Remembering that I want to use this to list the names of the other table if they have a higher grade average. There’s a small example of what I want to do (the bottom example is wrong):
select informacao.* from informacao, lista where informacao.id like lista.id
and 9<(SELECT AVG(nota) FROM lista GROUP BY id)
At the end of the query I wanted to be able to have the name of all those who had the average of notes higher than a chosen value.
When I get to my computer, I give an improved answer
– Rovann Linhalis
Thanks :) I have already managed to find a solution thanks to you. It looks like this: Select * from informacao Where 7 <= (select avg(note) from lista Where lista.id=informacao.id)
– Fábio Gouveia