0

I'm trying to write a trigger for calculating the average rating of an institution. The idea is this: When an impressin is added to the table, the average score should be calculated using the AVG function. Code:

CREATE TRIGGER 'ratein_up' AFTER INSERT ON 'impressin'
    FOR EACH ROW
    BEGIN
    SET @new_rat:=(SELECT AVG(Rating) FROM impressin);
    UPDATE feed-point SET OLD.AverageRating = @new_rat 
    WHERE id= NEW.idFeedPoint;
    END

Indicates an error in the line:UPDATE feed-point SET OLD.AverageRating = @new_rat WHERE id= NEW.idFeedPoint;

4
  • 2
    There are so many errors in the code that I'm voting to close as "too broad". You are using single quotes incorrectly around identifiers, you are doing some sort of subtraction after the update, you are attempting to update a row in the source table in an after update trigger. Commented Jun 10, 2018 at 21:30
  • This is not a minus, this is the name of my table.Single quotes formed PHP MyAdmin Commented Jun 10, 2018 at 21:40
  • Are you sure you even want a trigger for this derived data? Commented Jun 10, 2018 at 21:44
  • Извините за неприятность, я отредактировал триггер и протестировал его, он работает правильно. Необходимо было ввести название таблицы в кавычки. Исправленная строка: UPDATE 'feed-point' SET AverageRating = @new_rat WHERE id = NEW.idFeedPoint; Commented Jun 10, 2018 at 21:51

1 Answer 1

1

I'm sorry for the trouble, I edited the trigger and tested, it works correctly. It was necessary to take the name of the table into quotes. Corrected line

UPDATE `feed-point` SET AverageRating = @new_rat WHERE id= NEW.idFeedPoint;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.