5
I have the tables usuarios, usuario_voto, and classificacao_usuario.
Usuarios: system users table.
usuario_voto: table that stores a user’s vote on another.
classificacao_usuario: table that stores a user’s average of votes.
Functioning.
Each user has a table of classificao_usuario, with their average of votes.
The table usuario_voto has the columns usuario_votante, usuario_votado and nota .
Goal
When a user votes for another user(insert usuario_voto), I want to trigger a trigger where after the vote, is updated the table note column classificao_usuario. Trigger should take the average vote of this user that was voted on the table usuario_voto) .
I think the trigger select should stay 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 will look more like this
UPDATE classificacao_usuario SET nota = <MEDIA> WHERE id = <ID_DO_USUARIO_QUE_QUERO>