【发布时间】:2014-02-10 15:06:03
【问题描述】:
代码:
# Triggers for table Likes->News
CREATE TRIGGER `TriggerUpdateNewsAfterInsertLikes` AFTER INSERT ON `Likes`
FOR EACH ROW
BEGIN
UPDATE `News` SET
`CountUpLikes` = (SELECT COUNT(*) FROM `Likes` WHERE `NewsIdn` = NEW.`NewsIdn` AND `Type` = 'up'),
`CountDownLikes` = (SELECT COUNT (*) FROM `Likes` WHERE `NewsIdn` = NEW.`NewsIdn` AND `Type` = 'down'),
`CountFavorites` = (SELECT COUNT(*) FROM `Likes` WHERE `NewsIdn` = NEW.`NewsIdn` AND `IsFavorite` = 'yes');
END;
当我想在 phpmyadmin 中添加它时,我得到了错误:
#1064 - You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax
to use near '*) FROM `Likes` WHERE `NewsIdn` = NEW.`NewsIdn`
AND `Type` = 'down'),
`CountFav' at line 8
如果我使用id 而不是* 我会出错:
#1064 - You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax
to use near '' at line 9
请告诉我如何正确添加触发器?
【问题讨论】:
标签: mysql sql phpmyadmin triggers