mysql 目标表的结果是不可更新的,如何修复它?

yhqotfr8  于 12个月前  发布在  Mysql
关注(0)|答案(2)|浏览(138)

我试过使用CTE和子查询,它们都给出了相同的错误“The target table Result of the task is not updatable”。我试过谷歌,但我没有找到有用的资源。
customers table
热膨胀系数代码

with Result as
(
    select 
        *,
        row_number() over(partition by id order by id) as RowNo 
    from 
        customers
)
delete from Result 
where RowNo > 1;

字符串
子查询代码

delete Result 
from (select *, row_number() over(partition by id order by id) as RowNo 
      from customers) Result 
where Result.RowNo > 1;

cetgtptt

cetgtptt1#

图案:

DELETE t1
FROM table t1
JOIN table t2 ON t1.ident_column = t2.ident_column
             AND t1.order_column < t2.order_column

字符串

DELETE
FROM table t1
WHERE EXISTS ( SELECT NULL 
               FROM table t2
               WHERE t1.ident_column = t2.ident_column
                 AND t1.order_column < t2.order_column )


此模式删除ident_column重复的行,只保存order_column中具有最大值的行。

tez616oj

tez616oj2#

DELETE FROM customers 
WHERE id IN( 
           WITH cte AS (
               SELECT id, row_number() over(partition by id order by id) AS RowNo FROM customers) 
           SELECT id FROM cte WHERE RowNo>1
);

字符串
这个应该能用

相关问题