I have tables usuarios
, usuario_voto
, and classificacao_usuario
.
Usuarios:
system user table.
usuario_voto:
table that stores vote from one user to another.
classificacao_usuario:
table that stores average votes for a user.
Running.
Each user has a user-class table, where his average number of votes is listed.
The usuario_voto
table has the columns usuario_votante
, usuario_votado
and nota
.
Goal
When a user votes on another (insert usuario_voto
), I want a trigger to be triggered where after voting, the column note of the classificao_usuario
table is updated. The trigger must get the average vote for this user who was voted in the usuario_voto
table.
I think the trigger select should look more like this.
SELECT AVG(nota) FROM usuario_voto as v WHERE v.usuario_votado = <ID_DO_USUARIO_QUE_QUERO> group by v.usuario_votado
And the update I think would have been more like this
UPDATE classificacao_usuario SET nota = <MEDIA> WHERE id = <ID_DO_USUARIO_QUE_QUERO>