我正在尝试使用与'carretilla'相同的子查询来删除 这适用于SQL Server
DELETE FROM carretilla
WHERE carcod IN (
SELECT carcod
FROM carretilla
WHERE TIMESTAMPDIFF(MINUTE,carfch, NOW()) > 10
group BY carcod
);
我该怎么办? 感谢
答案 0 :(得分:0)
AFAIK您不能引用您删除的表或直接更新,但如果您使用子查询,服务器将创建一个临时记录集并让您进行删除,因此这应该有效:
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。