gpt4 book ai didi

mysql - 使用子查询删除 MySQL

转载 作者:行者123 更新时间:2023-11-29 22:10:09 24 4
gpt4 key购买 nike

我正在尝试使用同一个表“carretilla”的子查询来删除这适用于 SQL Server

DELETE FROM carretilla 
WHERE carcod IN (
SELECT carcod
FROM carretilla
WHERE TIMESTAMPDIFF(MINUTE,carfch, NOW()) > 10
group BY carcod
);

我该怎么做?谢谢

最佳答案

据我所知,您无法直接引用从中删除或更新的表,但如果您使用子查询,服务器将创建一个临时记录集并让您执行删除操作,因此这应该可行:

DELETE FROM carretilla 
WHERE carcod IN (
SELECT carcod FROM (
SELECT carcod FROM carretilla
WHERE TIMESTAMPDIFF(MINUTE,carfch, NOW()) > 10 group BY carcod
) temp_table
);

查看此sample SQL Fiddle .

关于mysql - 使用子查询删除 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31756154/

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