如何将SELECT语句用于UPDATE语句?

时间:2017-07-14 17:33:45

标签: mysql sql sql-update

我有 TRIGGER def get_number(self, bsObj): if self.get_data('text1', bsObj) > -1: return self.get_data('text1', bsObj) elif self.get_info('text', bsObj) > -1: return self.get_data('text', bsObj) else: return 0

AFTER INSERT

现在我也想做同样的事情BEGIN IF new.score IS NOT NULL THEN INSERT INTO reputations(event_table_id, type, score, question_id, post_id, table_code, comment_id, owner_id, date_time) SELECT new.id, new.type, new.score, t1.id, new.post_id, new.table_code, new.comment_id, new.author_id, UNIX_TIMESTAMP() FROM qanda t1 WHERE (EXISTS (SELECT 1 FROM qanda t2 WHERE ID = new.post_id AND t1.ID = t2.related) or t1.id = new.post_id) AND Type = 0; END IF; END 。我怎样才能做到这一点?

这是我尝试过的:

AFTER UPDATE

有人知道我应该写什么而不是BEGIN IF new.score IS NOT NULL THEN UPDATE reputations SET type = new.type, score = new.score, question_id = <I don't know>, post_id = new.post_id, table_code = new.table_code, comment_id = new.comment_id, owner_id = new.author_id, date_time = UNIX_TIMESTAMP() WHERE event_table_id = old.id END IF; END 部分吗?

0 个答案:

没有答案