gpt4 book ai didi

mysql - 如何在MySQL 8事件中执行多个DELETE查询

转载 作者:行者123 更新时间:2023-11-29 15:38:20 25 4
gpt4 key购买 nike

我尝试使用事件在一段时间后删除行。执行此操作时,我还有其他事情需要处理。我只想删除要在一段时间后删除的行。不太知道如何表达,但是当你查看代码时你就会明白:

CREATE EVENT IF NOT EXISTS `remove_links`
ON SCHEDULE EVERY 1 SECOND
ON COMPLETION PRESERVE
ENABLE
DO

DELETE FROM links WHERE time < (NOW() - INTERVAL 1 DAY) AND EXPIRE = 'A Day';
DELETE FROM links WHERE time < (NOW() - INTERVAL 1 WEEK) AND EXPIRE = 'A Week';
DELETE FROM links WHERE time < (NOW() - INTERVAL 1 MONTH) AND EXPIRE = 'A Month';

如果我只有一个 DELETE 语句,那么这是有效的,但是当我一次添加多个时,该事件只接受第一个,甚至没有注意到其余的(我在创建事件后查看了该事件,并且有只有一个 DELETE 语句 [始终是第一个])。

如果之前已经回答过这个问题,我很抱歉,我不知道要搜索什么。

最佳答案

DELETE FROM links WHERE (time < (NOW() - INTERVAL 1 DAY) AND EXPIRE = 'A Day') or 
( time < (NOW() - INTERVAL 1 WEEK) AND EXPIRE = 'A Week') or
(time < (NOW() - INTERVAL 1 MONTH) AND EXPIRE = 'A Month');

关于mysql - 如何在MySQL 8事件中执行多个DELETE查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57983615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com