gpt4 book ai didi

mysql - 如何删除重复行但保留 1 基于两列

转载 作者:行者123 更新时间:2023-11-29 00:34:59 25 4
gpt4 key购买 nike

我有一个名为 scheduler 的表。它包含以下列:

ID
sequence_id
schedule_time (timestamp)
processed
source_order

我需要从表中删除重复的行,但保留 1 行具有相同的 schedule_time 和 source_order 对于特定的 sequence_id where processed=0

最佳答案

DELETE yourTable FROM yourTable LEFT OUTER JOIN (
SELECT MIN(ID) AS minID FROM yourTable WHERE processed = 0 GROUP BY schedule_time, source_order
) AS keepRowTable ON yourTable.ID = keepRowTable.minID
WHERE keepRowTable.ID IS NULL AND processed = 0

我从这篇文章申请;P How can I remove duplicate rows?你见过吗?

--固定版本--

DELETE yourTable FROM yourTable LEFT OUTER JOIN (
SELECT MIN(ID) AS minID FROM yourTable WHERE processed = 0 GROUP BY schedule_time, source_order
) AS keepRowTable ON yourTable.ID = keepRowTable.minID
WHERE keepRowTable.minID IS NULL AND processed = 0

关于mysql - 如何删除重复行但保留 1 基于两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14767148/

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