当页面浏览量增加时,我想更新时间戳'lastpageview\u at'。我想我很接近,但我总是得到一个语法错误,有人知道为什么或有其他的解决办法吗?
我的触发器:
CREATE TRIGGER Update_lastpageview BEFORE UPDATE ON shortlinks
FOR EACH ROW BEGIN
IF OLD.pageviews <=> NEW.pageviews THEN
SET NEW.lastpageview_at = CURRENT_TIMESTAMP();
END IF;
END;
这是我的table:
CREATE TABLE `shortlinks` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`shortlink_id` varchar(40) NOT NULL DEFAULT '',
`pageviews` int(11) unsigned DEFAULT NULL,
`lastpageview_at` timestamp NULL DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `shortlink` (`shortlink`)
) ENGINE=InnoDB AUTO_INCREMENT=84 DEFAULT CHARSET=utf8;
1条答案
按热度按时间mqkwyuun1#
不等式运算符是
!=
或者<>
不是<=>
```delimiter $$
CREATE TRIGGER Update_lastpageview BEFORE UPDATE ON shortlinks
FOR EACH ROW BEGIN
IF OLD.pageviews <> NEW.pageviews THEN
SET NEW.lastpageview_at = NOW();
END IF;
END;$$